You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

20 lines
528 B

var swap = require('./swap');
var isSorted = require('./isSorted');
exports = function(arr) {
var cmp =
arguments.length > 1 && arguments[1] !== undefined
? arguments[1]
: isSorted.defComparator;
for (var i = 1, len = arr.length; i < len; i++) {
for (var j = i; j > 0; j--) {
if (cmp(arr[j], arr[j - 1]) < 0) {
swap(arr, j, j - 1);
} else {
break;
}
}
}
return arr;
};
module.exports = exports;