[Functional Programming] Make a flip and reverse functions
function f(...args) {
return args;
}
function flip(fn) {
return function flipped (arg1, arg2, ...args) {
return fn(arg2, arg1, ...args)
}
}
let z = flip(f)
console.log(z(1,2,3)) // [2,1,3]
function reverse(fn) {
return function reversed(...args) {
return fn(...args.reverse())
}
}
let r = reverse(f)
console.log(r(1,2,3)) // [3,2,1]