Skip to content

Instantly share code, notes, and snippets.

@jackcallister
Created April 25, 2020 09:25
Show Gist options
  • Save jackcallister/8087388ed04d3c3ad428a8f781104d60 to your computer and use it in GitHub Desktop.
Save jackcallister/8087388ed04d3c3ad428a8f781104d60 to your computer and use it in GitHub Desktop.
(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