summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-05 23:16:32 +0530
committerAndinus <andinus@nand.sh>2021-09-05 23:16:32 +0530
commit708ed21ef98343bf39c2426c762f6ce930955460 (patch)
treebe220aa2684eac99c6f5986b6d658d769cecb105
parent0fc602466192345311ba632da3ff456f20b9913c (diff)
downloadexercism-708ed21ef98343bf39c2426c762f6ce930955460.tar.gz
Clojure: Reverse String: Add solution
-rw-r--r--clojure/reverse-string/HELP.md57
-rw-r--r--clojure/reverse-string/README.md29
-rw-r--r--clojure/reverse-string/project.clj4
-rw-r--r--clojure/reverse-string/src/reverse_string.clj5
-rw-r--r--clojure/reverse-string/test/reverse_string_test.clj29
5 files changed, 124 insertions, 0 deletions
diff --git a/clojure/reverse-string/HELP.md b/clojure/reverse-string/HELP.md
new file mode 100644
index 0000000..d48c163
--- /dev/null
+++ b/clojure/reverse-string/HELP.md
@@ -0,0 +1,57 @@
+# Help
+
+## Running the tests
+
+Leiningen can be used to run the exercise's test by running the following command from the exercise's directory:
+
+```bash
+lein test
+```
+
+## REPL
+
+To use the REPL to run the exercise's test, run the following command from the exercise's directory:
+
+```bash
+$ lein repl
+```
+
+Then `require` the exercise's test namespace and the Clojure test namespace):
+
+```clojure
+;; replace <exercise> with the exercise's name
+=> (require '<exercise>-test)
+```
+
+Then call `run-tests` on `<exercise>-test`:
+
+```clojure
+;; replace <exercise> with the exercise's name
+=> (clojure.test/run-tests '<exercise>-test)
+```
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit src/reverse_string.clj` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Clojure track's documentation](https://exercism.org/docs/tracks/clojure)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [ClojureDocs](https://clojuredocs.org) A repository of language references and examples by function or keyword.
+- [/r/clojure](https://www.reddit.com/r/clojure) is the C# subreddit.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/clojure) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
\ No newline at end of file
diff --git a/clojure/reverse-string/README.md b/clojure/reverse-string/README.md
new file mode 100644
index 0000000..a29d2ac
--- /dev/null
+++ b/clojure/reverse-string/README.md
@@ -0,0 +1,29 @@
+# Reverse String
+
+Welcome to Reverse String on Exercism's Clojure Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Reverse a string
+
+For example:
+input: "cool"
+output: "looc"
+
+## Source
+
+### Created by
+
+- @sjwarner-bp
+
+### Contributed to by
+
+- @amscotti
+- @AndreaCrotti
+- @haus
+- @mtkp
+
+### Based on
+
+Introductory challenge to reverse an input string - https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb
\ No newline at end of file
diff --git a/clojure/reverse-string/project.clj b/clojure/reverse-string/project.clj
new file mode 100644
index 0000000..34c22bc
--- /dev/null
+++ b/clojure/reverse-string/project.clj
@@ -0,0 +1,4 @@
+(defproject reverse-string "0.1.0-SNAPSHOT"
+  :description "reverse-string exercise."
+  :url "https://github.com/exercism/clojure/tree/master/exercises/reverse-string"
+  :dependencies [[org.clojure/clojure "1.10.0"]])
diff --git a/clojure/reverse-string/src/reverse_string.clj b/clojure/reverse-string/src/reverse_string.clj
new file mode 100644
index 0000000..233bf9e
--- /dev/null
+++ b/clojure/reverse-string/src/reverse_string.clj
@@ -0,0 +1,5 @@
+(ns reverse-string)
+(require '[clojure.string :as s])
+
+(defn reverse-string [s]
+  (s/reverse s))
diff --git a/clojure/reverse-string/test/reverse_string_test.clj b/clojure/reverse-string/test/reverse_string_test.clj
new file mode 100644
index 0000000..f80d06a
--- /dev/null
+++ b/clojure/reverse-string/test/reverse_string_test.clj
@@ -0,0 +1,29 @@
+(ns reverse-string-test
+  (:require [clojure.test :refer [deftest is]]
+            reverse-string))
+
+(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)))))