Simplified rearg snippet

This commit is contained in:
Bruce Feldman
2018-08-12 12:32:39 -04:00
parent 025f4f5534
commit 256f88b277
2 changed files with 3 additions and 15 deletions

View File

@ -1,8 +1,2 @@
const rearg = (fn, indexes) => (...args) =>
fn(
...args.reduce(
(acc, val, i) => ((acc[indexes.indexOf(i)] = val), acc),
Array.from({ length: indexes.length })
)
);
const rearg = (fn, indexes) => (...args) => fn(...indexes.map(idx => args[idx]));
module.exports = rearg;