DEV Community

Discussion on: Are one-liners always the best solutions?

Collapse
 
aminmansuri profile image
hidden_dude

I don't get it.
I tried with:

const arr = [100, 22, 22, 44, 44, 44,44];
Enter fullscreen mode Exit fullscreen mode

It doesn't seem to work.

Collapse
 
slnsrn profile image
Selin Serin

sorry, i forgot to mention.
You need to write the sort function explicitly. Otherwise sorts as a string and 4 > 1 :)

   arr.sort((a, b) => a - b)
Enter fullscreen mode Exit fullscreen mode