I'm a coder who has worn a lot of hats, from individual contributor to lead engineer to "CTO" (yes, in quotes, make of that what you will!). I've a lot to learn and hopefully some to share as well.
This is actually less efficient than the reduce method though (O(nlogn) vs O(n)) so I would use reduce if the array is VERY large (at least several millions elements).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a good solution, but I tend to prefer sorting:
This is actually less efficient than the reduce method though (O(nlogn) vs O(n)) so I would use reduce if the array is VERY large (at least several millions elements).