Shorter stableSort function + use const

This commit is contained in:
simov
2018-02-07 11:17:57 +02:00
parent 276b57a9ca
commit bc6c8633c1
3 changed files with 11 additions and 15 deletions

View File

@ -12,11 +12,11 @@ test('Testing stableSort', (t) => {
// test if js engine's Array#sort implementation is stable
// https://gist.github.com/leeoniya/5816476
var str = 'abcdefghijklmnopqrstuvwxyz';
var compare = (a, b) => ~~(str.indexOf(b) / 2.3) - ~~(str.indexOf(a) / 2.3);
const str = 'abcdefghijklmnopqrstuvwxyz';
const compare = (a, b) => ~~(str.indexOf(b) / 2.3) - ~~(str.indexOf(a) / 2.3);
var input = str.split('');
var output = stableSort(input, compare);
const input = str.split('');
const output = stableSort(input, compare);
t.equal(output.join(''), 'xyzvwtursopqmnklhijfgdeabc');
t.notDeepEqual(input, output);