# 4d47's solution

## to Reverse String in the Clojure Track

Published at Jul 13 2018 · 0 comments
Instructions
Test suite
Solution

Reverse a string

For example: input: "cool" output: "looc"

## Source

Introductory challenge to reverse an input string https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

### reverse_string_test.clj

``````(ns reverse-string-test
(:require [clojure.test :refer [deftest is]]
reverse-string))

(deftest empty-string-test
(is (= "" (reverse-string/reverse-string ""))))

(deftest a-word-test
(is (= "tobor" (reverse-string/reverse-string "robot"))))

(deftest capitalised-word-test
(is (= "nemaR" (reverse-string/reverse-string "Ramen"))))

(deftest sentence-with-punctuation-test
(is (= "!yrgnuh m'I" (reverse-string/reverse-string "I'm hungry!"))))

(deftest palindrome-test
(is (= "racecar" (reverse-string/reverse-string "racecar"))))``````
``````(ns reverse-string
(:require [clojure.string :rename {reverse reverse-string}]))

(defn ^String reverse-string-1 [^CharSequence s]
(.. (StringBuilder. s) reverse toString))

(defn ^String reverse-string-2 [^CharSequence s]
(apply str (reverse s)))``````