diff options
Diffstat (limited to 'node_modules/array-each/index.js')
-rw-r--r-- | node_modules/array-each/index.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/node_modules/array-each/index.js b/node_modules/array-each/index.js new file mode 100644 index 000000000..12afef4d3 --- /dev/null +++ b/node_modules/array-each/index.js @@ -0,0 +1,46 @@ +/*! + * array-each <https://github.com/jonschlinkert/array-each> + * + * Copyright (c) 2015, 2017, Jon Schlinkert. + * Released under the MIT License. + */ + +'use strict'; + +/** + * Loop over each item in an array and call the given function on every element. + * + * ```js + * each(['a', 'b', 'c'], function(ele) { + * return ele + ele; + * }); + * //=> ['aa', 'bb', 'cc'] + * + * each(['a', 'b', 'c'], function(ele, i) { + * return i + ele; + * }); + * //=> ['0a', '1b', '2c'] + * ``` + * + * @name each + * @alias forEach + * @param {Array} `array` + * @param {Function} `fn` + * @param {Object} `thisArg` (optional) pass a `thisArg` to be used as the context in which to call the function. + * @return {undefined} + * @api public + */ + +module.exports = function each(arr, cb, thisArg) { + if (arr == null) return; + + var len = arr.length; + var idx = -1; + + while (++idx < len) { + var ele = arr[idx]; + if (cb.call(thisArg, ele, idx, arr) === false) { + break; + } + } +}; |