array sorting (js)

by default, when we use sort, it compares by string, which is what we don’t want.

Custom Sorting

Thus, we use custom sorting

do it like so…

you can also see the ordering of integers by subtracting them. positive means left number is larger. negative means left number is smaller.

get maximum

get 2nd max

get minimum

Sorting Objects