Before testing install dependencies npm i
or yarn
.
Run tests npm run test
or yarn test
How returned value of sort()
implementation works:
Return value | sort order |
---|---|
> 0 |
sort a after b |
< 0 |
sort a before b |
=== 0 |
keep original order of a and b |
So, the compare function has the following form:
function compareFn(a, b) {
if (a is less than b by some ordering criterion) {
return -1;
}
if (a is greater than b by the ordering criterion) {
return 1;
}
// a must be equal to b
return 0;
}