Runs an operation for each pair in an array.
Install with npm:
$ npm install --save pair-foreach
const pairForEach = require("pair-foreach");
const pairs = [
[1, 10],
[2, 9],
[3, 8],
[4, 7],
[5, 6]
];
pairForEach(pairs, (elem1, elem2) => {
console.log(elem1 * elem2);
});
The first argument for pairForEach
must be an array of 2-length arrays.
The second argument must be a function with between 2 and 4 arguments. The first 2 arguments are elements, the 3rd one is the index, and the 4th one is the original array.