The other thing I did was write a reduce function to sort items in an array without modifying the original array.

.... I really need to find a job so I stop being the sole driver of my time. XD

  • 0
    Now with more binary search!
  • 0
    Why 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
  • 0
    @AmyShackles Ooh, I like the binary search on insertion, never thought of it!
  • 0
    @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. :)
Add Comment