1 | import cmp from './_cmp';
|
2 | function insertionSortPair$(x, fc, m) {
|
3 | var X = x.length, diff = x !== m;
|
4 | for (var i = X - 2; i >= 0; i--) {
|
5 | var xv = x[i], mv = m[i];
|
6 | for (var j = i + 1; j < X; j++) {
|
7 | if (fc(mv, m[j]) <= 0)
|
8 | break;
|
9 | if (true)
|
10 | x[j - 1] = x[j];
|
11 | if (diff)
|
12 | m[j - 1] = m[j];
|
13 | }
|
14 | if (true)
|
15 | x[j - 1] = xv;
|
16 | if (diff)
|
17 | m[j - 1] = mv;
|
18 | }
|
19 | return x;
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function insertionSort$(x, fc = null, fm = null) {
|
29 | var fc = fc || cmp;
|
30 | if (fm)
|
31 | return insertionSortPair$(x, fc, x.map(fm));
|
32 | else
|
33 | return insertionSortPair$(x, fc, x);
|
34 | }
|
35 | export default insertionSort$;
|
36 |
|
\ | No newline at end of file |