Sorting a string alphabetically by line in Clojure(Script) -
suppose s
string defined follows:
;; s b c
is there clojure operation sort-alphabetically
(that works in clojurescript) such (sort-alphabetically s)
generates following string?
;; (sort-alphabetically s) => b c
the following code snippet want:
(require '[clojure.string :as str]) (def s "c\nb\na") (->> s (str/split-lines) ; split string sequence of lines (sort) ; sort sequence using natural order (for strings alphabetical order) (str/join "\n")) ; join elements of sorted sequence using \n producing multiline string ;; => "a\nb\nc"
Comments
Post a Comment