UNPKG

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