This file contains hidden or 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
// Watch https://youtu.be/KvYzGsz5vHA to see how I coded this with some commentary | |
let add = (n, v) => !n ? { v } : { ...n, [v < n.v]: add(n[v < n.v], v) } | |
let flat = n => !n ? [] : [...flat(n[!0]), n.v, ...flat(n[!1])] | |
let bsort = vs => flat(vs.reduce(add, null)) | |
// 182 characters with nice formatting | |
let add=(n,v)=>!n?{v}:{...n,[v<n.v]:add(n[v<n.v],v)} | |
let flat=n=>!n?[]:[...flat(n[!0]),n.v,...flat(n[!1])] | |
let bsort=vs=>flat(vs.reduce(add,null)) |
NewerOlder