my-idlers/node_modules/collect.js/dist/methods/sort.js

21 lines
409 B
JavaScript
Raw Normal View History

'use strict';
module.exports = function sort(fn) {
var collection = [].concat(this.items);
if (fn === undefined) {
if (this.every(function (item) {
return typeof item === 'number';
})) {
collection.sort(function (a, b) {
return a - b;
});
} else {
collection.sort();
}
} else {
collection.sort(fn);
}
return new this.constructor(collection);
};