Merge pull request #710 from Bruce-Feldman/Simplify-rearg

[ENHANCEMENT] Simplified Rearg Snippet
This commit is contained in:
Angelos Chalaris
2018-08-13 14:25:50 +03:00
committed by GitHub
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(i => args[i]));
module.exports = rearg;