1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
| }
| }
| };
|
|