Skip to content

Commit 0728085

Browse files
author
AndreyGeonya
committed
add mergesort jsdoc
1 parent 43b6652 commit 0728085

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/sorting/insertion-binary-sort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@
5555

5656
exports.insertionBinarySort = insertionBinarySort;
5757

58-
}(typeof exports === 'undefined' ? window : exports));
58+
})(typeof window === 'undefined' ? module.exports : window);

src/sorting/insertionsort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141

4242
exports.insertionSort = insertionSort;
4343

44-
}(typeof exports === 'undefined' ? window : exports));
44+
})(typeof window === 'undefined' ? module.exports : window);

src/sorting/lsd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848

4949
exports.lsd = lsd;
5050

51-
}(typeof exports === 'undefined' ? window : exports));
51+
})(typeof window === 'undefined' ? module.exports : window);

src/sorting/mergesort.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,22 @@
7575
}
7676

7777
/**
78-
* Initial call to the mergesort method
78+
* Merge sort algorithm.<br><br>
79+
* Time complexity: O(N logN).
80+
*
81+
* @example
82+
*
83+
* var sort = require('path-to-algorithms/src' +
84+
* '/sorting/mergesort').mergesortSort;
85+
* console.log(sort([2, 5, 1, 0, 4])); // [ 0, 1, 2, 4, 5 ]
7986
*
8087
* @public
81-
* @param {array} array The array which will be sorted
82-
* @returns {array} Sorted array
88+
* @module sorting/mergesort
89+
* @param {Array} array Input array.
90+
* @param {Function} cmp Optional. A function that defines an
91+
* alternative sort order. The function should return a negative,
92+
* zero, or positive value, depending on the arguments.
93+
* @return {Array} Sorted array.
8394
*/
8495
return function (array, cmp) {
8596
cmp = cmp || compare;
@@ -90,4 +101,4 @@
90101

91102
exports.mergeSort = mergeSort;
92103

93-
}(typeof exports === 'undefined' ? window : exports));
104+
})(typeof window === 'undefined' ? module.exports : window);

src/sorting/msd.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@
5454
* @param {Number} d Optional. Digit from which sorting should start.
5555
* @return {Array} Sorted array.
5656
*/
57-
5857
function msd(arr, d) {
5958
d = d || 0;
6059
sort(arr, 0, arr.length - 1, d);
6160
return arr;
6261
}
6362

6463
exports.msd = msd;
65-
}(typeof exports === 'undefined' ? window : exports));
64+
})(typeof window === 'undefined' ? module.exports : window);

0 commit comments

Comments
 (0)