mirror of
https://github.com/cp6/my-idlers.git
synced 2025-04-21 02:28:35 +00:00
21 lines
No EOL
409 B
JavaScript
21 lines
No EOL
409 B
JavaScript
'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);
|
|
}; |