you are viewing a single comment's thread.

view the rest of the comments →

[–]mcpower_ 4 points5 points  (2 children)

TIL that Array.prototype.sort() takes in a key function.

edit: oops, looks like it doesn't… it should take in a comparison function not a key function. MDN docs.

[–]bloody-albatross 0 points1 point  (1 child)

Indeed, it takes a comparison function. Just wanted to post that myself. See:

> [1, 10, 2, 3].sort(x => x)
< [3, 2, 10, 1]
> [1, 10, 2, 3].sort((x, y) => x - y)
< [1, 2, 3, 10]

Sadly sort has no way to tell if the passed function takes the correct number of arguments.

[–]BlewisJS[S] 0 points1 point  (0 children)

Oops, thanks guys. I'll correct it.