UNPKG

3.23 kBMarkdownView Raw
1Arranges values in an order. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:]
2> Similar: [sort], [merge].<br>
3> This is part of package [extra-array].
4
5[extra-array]: https://www.npmjs.com/package/extra-array
6
7```javascript
8array.insertionSort$(x, [fc], [fm]);
9// x: an array (updated)
10// fc: compare function (a, b)
11// fm: map function (v, i, x)
12// --> x
13```
14
15```javascript
16const array = require('extra-array');
17
18var x = [-2, -3, 1, 4];
19array.insertionSort$(x);
20// [ -3, -2, 1, 4 ] (compares numbers)
21
22x;
23// [ -3, -2, 1, 4 ]
24
25var x = [-2, -3, 1, 4];
26array.insertionSort$(x, (a, b) => Math.abs(a) - Math.abs(b));
27// [ 1, -2, -3, 4 ]
28
29var x = [-2, -3, 1, 4];
30array.insertionSort$(x, null, v => Math.abs(v));
31// [ 1, -2, -3, 4 ]
32```
33
34### references
35
36- [Data.Sort.sortBy: Haskell](https://hackage.haskell.org/package/sort-1.0.0.0/docs/Data-Sort.html#v:sortBy)
37- [Array.prototype.sort: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
38- [Bubble Sort: Wikipedia](https://en.wikipedia.org/wiki/Bubble_sort)
39- [bubble-sort: @tristanls](https://www.npmjs.com/package/bubble-sort)
40- [algo-sort-bubble: @bredele](https://www.npmjs.com/package/algo-sort-bubble)
41- [bubblesort: @addyosmani](https://www.npmjs.com/package/bubblesort)
42- [sort-bubble: @lukebro](https://www.npmjs.com/package/sort-bubble)
43- [bubble-sort-js: @JacopoDaeli](https://www.npmjs.com/package/bubble-sort-js)
44- [bubble-srt: @abranhe](https://www.npmjs.com/package/bubble-srt)
45- [b-sort: alkuhar](https://www.npmjs.com/package/b-sort)
46- [@clarketm/superbubblesort: @clarketm](https://www.npmjs.com/package/@clarketm/superbubblesort)
47- [sort-algorithms-js: @eyas-ranjous](https://www.npmjs.com/package/sort-algorithms-js)
48- [sort-types: @dalalayan1](https://www.npmjs.com/package/sort-types)
49- [sorting-helpers: @AntoniAngga](https://www.npmjs.com/package/sorting-helpers)
50- [sorti: @nadavgld](https://www.npmjs.com/package/sorti)
51- [sortie: @mustafar](https://www.npmjs.com/package/sortie)
52- [sorting: @lakhaNamdhari](https://www.npmjs.com/package/sorting)
53- [plentiful: @ajnauleau](https://www.npmjs.com/package/plentiful)
54- [sort-all-in-one: @OnlyRefat](https://www.npmjs.com/package/sort-all-in-one)
55- [sort-algorithms: @sombrerolgringo](https://www.npmjs.com/package/sort-algorithms)
56- [sorting-algorithms: @luongnv89](https://www.npmjs.com/package/sorting-algorithms)
57- [js-sorting: @jasonheecs](https://www.npmjs.com/package/@jasonheecs/js-sorting)
58- [js-sorting-algo: @kumar-gaurav-mishra](https://www.npmjs.com/package/js-sorting-algo)
59- [@ds-javascript/sort: @opensourcedj217](https://www.npmjs.com/package/@ds-javascript/sort)
60- [best-sort: @agniswarm](https://www.npmjs.com/package/best-sort)
61
62[sort]: https://github.com/nodef/extra-array/wiki/sort
63[sort$]: https://github.com/nodef/extra-array/wiki/sort$
64[merge]: https://github.com/nodef/extra-array/wiki/merge
65[:running:]: https://npm.runkit.com/@extra-array/insertion-sort-update
66[:vhs:]: https://asciinema.org/a/334733
67[:package:]: https://www.npmjs.com/package/@extra-array/insertion-sort-update
68[:moon:]: https://www.npmjs.com/package/@extra-array/insertion-sort-update.min
69[:ledger:]: https://unpkg.com/@extra-array/insertion-sort-update/