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.

index.js 630B

123456789101112131415161718192021222324252627282930313233
  1. /*!
  2. * arr-filter <https://github.com/jonschlinkert/arr-filter>
  3. *
  4. * Copyright (c) 2014-2015, 2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. var makeIterator = require('make-iterator');
  9. module.exports = function filter(arr, fn, thisArg) {
  10. if (arr == null) {
  11. return [];
  12. }
  13. if (typeof fn !== 'function') {
  14. throw new TypeError('expected callback to be a function');
  15. }
  16. var iterator = makeIterator(fn, thisArg);
  17. var len = arr.length;
  18. var res = arr.slice();
  19. var i = -1;
  20. while (len--) {
  21. if (!iterator(arr[len], i++)) {
  22. res.splice(len, 1);
  23. }
  24. }
  25. return res;
  26. };