Без опису

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*!
  2. * array-each <https://github.com/jonschlinkert/array-each>
  3. *
  4. * Copyright (c) 2015, 2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. /**
  9. * Loop over each item in an array and call the given function on every element.
  10. *
  11. * ```js
  12. * each(['a', 'b', 'c'], function(ele) {
  13. * return ele + ele;
  14. * });
  15. * //=> ['aa', 'bb', 'cc']
  16. *
  17. * each(['a', 'b', 'c'], function(ele, i) {
  18. * return i + ele;
  19. * });
  20. * //=> ['0a', '1b', '2c']
  21. * ```
  22. *
  23. * @name each
  24. * @alias forEach
  25. * @param {Array} `array`
  26. * @param {Function} `fn`
  27. * @param {Object} `thisArg` (optional) pass a `thisArg` to be used as the context in which to call the function.
  28. * @return {undefined}
  29. * @api public
  30. */
  31. module.exports = function each(arr, cb, thisArg) {
  32. if (arr == null) return;
  33. var len = arr.length;
  34. var idx = -1;
  35. while (++idx < len) {
  36. var ele = arr[idx];
  37. if (cb.call(thisArg, ele, idx, arr) === false) {
  38. break;
  39. }
  40. }
  41. };