Created
April 25, 2020 09:25
-
-
Save jackcallister/8087388ed04d3c3ad428a8f781104d60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as str]) | |
(defn remove-punc [s] | |
(clojure.string/replace s #"[.!?\\-]" "")) | |
(defn split-to-words [s] | |
(clojure.string/split s #" ")) | |
(defn sort-by-alpha [coll] | |
(sort-by clojure.string/lower-case coll)) ; call lower-case in the comparator (x y) | |
(defn sort-words [s] | |
(->> s | |
remove-punc | |
split-to-words | |
sort-by-alpha | |
vec)) | |
(= (sort-words "Clojure is a fun language!") ["a" "Clojure" "fun" "is" "language"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment