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
409 B

4 years ago
  1. 'use strict';
  2. module.exports = function sort(fn) {
  3. var collection = [].concat(this.items);
  4. if (fn === undefined) {
  5. if (this.every(function (item) {
  6. return typeof item === 'number';
  7. })) {
  8. collection.sort(function (a, b) {
  9. return a - b;
  10. });
  11. } else {
  12. collection.sort();
  13. }
  14. } else {
  15. collection.sort(fn);
  16. }
  17. return new this.constructor(collection);
  18. };