[].sort()
can take a compare function
the compare function
can be given as the only parameter to sort()
(and gets used by it)
is called with two values to be compared
is called multiple times (depending how the sort algorithm is implemented)
the return value of the compare function indicates how the two values compare
examples
sort numbers
sort number-like values
custom compare algorithm
Links
Very detailed description of how `sort()` works.
Announcement of this kata on twitter.
Required Knowledge
- `array.sort()` basics (Array API)
Related Katas
Array API
array.sort()
basicsarray.sort()
can take a compare functionarray.shift()
(as introduced in ES3)array.push()
(as introduced in ES3)Array.from()
Array.of()
array.fill()
array.find()
array.findIndex()
array.entries()
array.keys()
array.values()
array.includes()
array.toReversed()
Difficulty Level
INTERMEDIATE
First Published
23 October 2015
Stats
9 tests to solve