Skip to content

Instantly share code, notes, and snippets.

@youaresofunny
Last active January 22, 2019 12:42
Show Gist options
  • Save youaresofunny/e3adfd8a173927106da393ef3937b92c to your computer and use it in GitHub Desktop.
Save youaresofunny/e3adfd8a173927106da393ef3937b92c to your computer and use it in GitHub Desktop.
const test = [1,2,3,4];
const processors = [
x => x * 2,
x => x * 3,
x => x * 4,
x => x * 5
];
const zipFn = test.map((e, idx) => processors[idx](e));
const { res } = test.reduce(({ processors, res }, e, idx) => ({
processors,
res: res + processors[idx](e)
}),
{
processors,
res: 0
});
console.log(zip) // [ 2, 6, 12, 20 ]
console.log(res) // 40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment