Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
AmyShackles354937dNow with more binary search!
CptFox169437dWhy not simply shallow clone your array before using sort on it? Would probably be simpler and higher perf (although js doesn't really make cloning intuitive...)
I do find the idea of using a reduce operation to implement basically an insertion sort.
Just one more nitpick : what's the point of checking if the accumulator is an array if you're gonna treat it as such anyway in the rest of the code? (I might have missed it, but I don't see the check's purpose)
Sorry to be so critical about your code, I hope you see it as the genuine attempt at constructive criticism I hope to make; and I do want to emphasize that I find the idea of using reduce to make an insertion sort interesting, and now wonder how many sort algorithms could be written similarly
AmyShackles354937d@CptFox Cloning and sorting would definitely be higher perf and simpler (at least if the cloning process were straightforward as in the case of all the items in the array being primitives).
This really just started because one of my friends made a comment about wondering if a reduce could be utilized to perform non-mutative sorting and I'm a sucker for unanswered questions.
As for the array check, it's probably completely unnecessary. When I first started working on it, I tiredly managed to make it change type midway through, so that was mostly just for my own sanity moving forward. XD
I really appreciate constructive criticism. I didn't really get it at my last job and it's something I get a lot of value from. :)