I find Array.prototype.reduce the ideal candidate for asymmetric input/output and it also allows us to forgo creating multiple arrays in memory, so the first part of my solution would look like this:
For the second part, I would utilize that 0 (equal sort value) it's coerced to false when using || and that string.prototype.localeCompare returns a number.
I find
Array.prototype.reducethe ideal candidate for asymmetric input/output and it also allows us to forgo creating multiple arrays in memory, so the first part of my solution would look like this:For the second part, I would utilize that 0 (equal sort value) it's coerced to false when using
||and that string.prototype.localeCompare returns a number.Nice one!
For future puzzle i actually decided to rely a lot of reduce.
Must say this looks a bit cleaner.
Map made more sense if it was just the one array loop that we had to format.
Thanks for this wonderful alternative Alex 👏