bobbicodes / bobbi-lisp

Interactive Lisp environment for learning Clojure
https://bobbicodes.github.io/bobbi-lisp/
0 stars 0 forks source link

Sorting behavior #31

Open bobbicodes opened 11 months ago

bobbicodes commented 11 months ago

When I found out javascript's sort() function takes an optional compare function I used that in sort-by, but now I realize that the expected behavior was lost and now I'm not sure how to restore it while keeping the ability to pass a key function to sort-by.

The default behavior works by converting the elements to strings and using each of their unicode values. This is what allows this to work:

(sort-by #(.toLowerCase %) (re-seq #"\w+" "Have a nice day."))
=> ["a" "day" "Have" "nice"]

I think I need to better understand how the compare functions work to know how to solve it, but one thought is to add special cases for if the items are strings.