Array.prototype.map()
to reorder arguments based on indexes
....
) to pass the transformed arguments to fn
.const rearg = (fn, indexes) => (...args) => fn(...indexes.map(i => args[i]));
var rearged = rearg(
function(a, b, c) {
return [a, b, c];
},
[2, 0, 1]
);
rearged('b', 'c', 'a'); // ['a', 'b', 'c']
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️