DEV Community

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

Collapse
 
slnsrn profile image
Selin Serin • Edited

this can be an alternative one line solution.
here

Alt text of image

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
Collapse
 
jcubic profile image
Jakub T. Jankiewicz

Clever.