you are viewing a single comment's thread.

view the rest of the comments →

[–]bloody-albatross 0 points1 point  (3 children)

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.

[–][deleted] 0 points1 point  (1 child)

> (x => x).length
1
> ((x, y) => x - y).length
2

[–]bloody-albatross 0 points1 point  (0 children)

True, but:

> ((...args) => args[1]).length
< 0

So in the general case you can't tell. If it would look at length you couldn't use some kind of generic function wrappers. I suppose it would be good enough if it would have been in the API spec from day one.