|
5 | 5 | return a - b;
|
6 | 6 | }
|
7 | 7 |
|
8 |
| - /** |
9 |
| - * Shellsort |
10 |
| - * |
11 |
| - * Shellsort uses the gaps 701, 301, 132, 57, 23, 10, 4, 1 and uses |
12 |
| - * insertion sort to sort the sub-arrays which match for the different gaps. |
13 |
| - */ |
14 | 8 | var shellSort = (function () {
|
15 | 9 |
|
16 | 10 | var gaps = [701, 301, 132, 57, 23, 10, 4, 1];
|
17 | 11 |
|
18 | 12 | /**
|
19 |
| - * Shellsort which uses the gaps in the lexical scope of the IIFE. |
| 13 | + * Shellsort which uses the gaps 701, 301, 132, 57, 23, 10, 4, 1 and |
| 14 | + * insertion sort to sort sub-arrays which match for the different gaps. |
| 15 | + * |
| 16 | + * @example |
| 17 | + * |
| 18 | + * var sort = require('path-to-algorithms/src/' + |
| 19 | + * 'sorting/shellsort').shellSort; |
| 20 | + * console.log(sort([2, 5, 1, 0, 4])); // [ 0, 1, 2, 4, 5 ] |
20 | 21 | *
|
21 | 22 | * @public
|
22 |
| - * @param {array} array Array which should be sorted |
23 |
| - * @return {array} Sorted array |
| 23 | + * @module sorting/shellsort |
| 24 | + * @param {Array} array Input array. |
| 25 | + * @param {Function} cmp Optional. A function that defines an |
| 26 | + * alternative sort order. The function should return a negative, |
| 27 | + * zero, or positive value, depending on the arguments. |
| 28 | + * @return {Array} Sorted array. |
24 | 29 | */
|
25 | 30 | return function (array, cmp) {
|
26 | 31 | cmp = cmp || compare;
|
|
0 commit comments