Last active
November 19, 2021 19:13
-
-
Save kesava/4fde9814ca00ac5aa3570ca926d613b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function requireAll (fn) { | |
return function(...args) { | |
if (fn.length === args.length) { | |
return fn.apply(this, args); | |
} else { | |
console.error("All args are required") | |
// throw new Error("All the arguments are required."); | |
} | |
} | |
} | |
const add = (a,b,c) => a + b + c; | |
const a = requireAll(add); | |
// console.log({ a: a.toString() }) | |
console.log({ a: a(1,2,3,4) }); | |
console.log({ b: a(1,2,3) }); // 6 | |
console.log({ c: a(1) }); | |
console.log({ d: a(1,2,7) }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment