-
Notifications
You must be signed in to change notification settings - Fork 0
reverse
Subhajit Sahu edited this page Aug 7, 2022
·
1 revision
Generate a parameter-reversed version of a function.
function reverse(x)
// x: a function
const xasyncfn = require('extra-async-function');
function divide(x, y) {
return x/y;
}
var fn = xasyncfn.reverse(divide);
fn(2, 4);
// → 2
fn(2, 6);
// → 3
fn(2, 8);
// → 4
var array = [1];
function push(...args) {
array.push(...args);
}
var fn = xasyncfn.reverse(push);
fn(2, 3, 4); // push(2, 3, 4) in reverse order
array;
// → [1, 4, 3, 2]