🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of nihilismus

nihilismus's solution

to Reverse String in the Clojure Track

Published at Sep 06 2020 · 0 comments
Test suite

Reverse a string

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


You can not use the reverse function, but you can use any of the other core functions.


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.


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

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

(deftest a-letter-test
  (is (= "I" (reverse-string/reverse-string "I"))))

(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"))))

(deftest even-sized-word-test
  (is (= "reward" (reverse-string/reverse-string "drawer"))))

(deftest long-string-test
  (let [s (reduce str (repeat 1000 "overflow?"))
        rs (reduce str (repeat 1000 "?wolfrevo"))]
    (is (= rs (reverse-string/reverse-string s)))))
(ns reverse-string)

(defn reverse-string [string]
  (apply str (into '() string)))

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?