I’m translating some
Clojure code to
Select only unique objects from a list
const myDistinctArray = [
// This one presumes unique "id" === unique object
let uniqueObjArray = [
objArray.map((item) => [item["id"], item])
(distinct my-object-list) // that's it
Why does the Clojure one work?
Clojure promotes immutability by default, and this includes maps. So maps are compared directly by value and not by reference or identity.
The beautiful thing about Clojure is how expressive the language is and how much you can say with very few lines of code.
Read this post and more on my Typeshare Social Blog