Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Created January 3, 2019 21:29
Show Gist options
  • Save miladvafaeifard/d3b86b11298d50ee10ddd36d634bfc55 to your computer and use it in GitHub Desktop.
Save miladvafaeifard/d3b86b11298d50ee10ddd36d634bfc55 to your computer and use it in GitHub Desktop.
js functional programming
const once = (fn) => {
return (...args) => {
fn && fn(...args);
fn = null
}
}
const thisManyTimes = (fn, limit) => {
return (...args) => {
if(limit > 0) {
limit--;
return fn(...args);
}
}
}
let log = once(console.log);
log('hello');
log('hello');
log('hello');
log = thisManyTimes(console.log, 2);
log('Test');
log('Test');
log('Test');
log('Test');
log('Test');
log('Test');
log('Test');
log('Test');
const factUp = (n, f = 1) => n <= f? f : f * factUp(n , f + 1);
console.log(factUp(4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment