Created
June 29, 2021 06:39
-
-
Save dfuenzalida/6d5b99d94949e4642140d43f86ae9dfa to your computer and use it in GitHub Desktop.
Sort strings numerically in Clojure
This file contains 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
(defn digits-in-str [s] | |
(->> (re-seq #"\d+" s) first)) | |
(def items ["item_20" "item_11" "item_1" "item_120"]) | |
(comment | |
(sort-by (comp clojure.edn/read-string digits-in-str) items) | |
;; => ("item_1" "item_11" "item_20" "item_120") | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment