-
Notifications
You must be signed in to change notification settings - Fork 5
adjacentCombine
Subhajit Sahu edited this page May 3, 2023
·
1 revision
Combine adjacent values of an array.
function adjacentCombine(x, fc, acc)
// x: an array
// fc: combine function (u, v)
// acc: initial value
const xarray = require('extra-array');
var x = [1, 2, 3, 4];
xarray.adjacentCombine(x, (u, v) => v-u, 0);
// → [ 1, 1, 1, 1 ]
xarray.adjacentCombine(x, (u, v) => u*v, 1);
// → [ 1, 2, 6, 12 ]
xarray.adjacentCombine(x, (u, v) => u+v, 10);
// → [ 11, 3, 5, 7 ]