re: Keeping Your Code Simple VIEW POST

re: Sometimes, there's an even simpler solution: const strs = ['hello', 'goodbye', 'farewell', 'aloha']; strs.sort((str1, str2) => str2.length -...

i thought the same... and if you have strings with numbers, then add a return (a-b) or something...


Seems that sort has worse performance compared to reduce. Reduce is O(n) while sort is O(n long)

Yes, the performance is worse. But unless you need the solution to scale to arrays with more than a few thousand words, this will hardly be an issue.

True. Just wrote that because it wasn't mentioned anywhere and someone might care about it.

valid point but I agree with Alex... not sure it would really be a thing in an implementation like this

code of conduct - report abuse