Skip to content

Instantly share code, notes, and snippets.

@kesava
Last active November 19, 2021 19:13
Show Gist options
  • Save kesava/4fde9814ca00ac5aa3570ca926d613b4 to your computer and use it in GitHub Desktop.
Save kesava/4fde9814ca00ac5aa3570ca926d613b4 to your computer and use it in GitHub Desktop.
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