forked from Tinkoff/utils.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheach.ts
More file actions
23 lines (21 loc) · 636 Bytes
/
each.ts
File metadata and controls
23 lines (21 loc) · 636 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import curryN from '../function/curryN';
import { each } from '../typings/types';
/**
* Iterate over an input `list`, calling a provided function `fn` for each
* element in the list.
*
* @param {Function} fn The function to invoke. Receives three argument: `value`, `index`, `arr`.
* @param {Array} arr The list to iterate over.
* @example
*
* var printXPlusFive = x => console.log(x + 5);
* each(printXPlusFive, [1, 2, 3]);
* // logs 6
* // logs 7
* // logs 8
*/
export default curryN(2, (fn, arr = []) => {
for (let i = 0; i < arr.length; i++) {
fn(arr[i], i, arr);
}
}) as typeof each