Skip to content

Instantly share code, notes, and snippets.

@asduser
Created August 25, 2016 19:20
Show Gist options
  • Save asduser/3a0ef85b0d60cc116560560f460d92c6 to your computer and use it in GitHub Desktop.
Save asduser/3a0ef85b0d60cc116560560f460d92c6 to your computer and use it in GitHub Desktop.
A way to modify an internal function checking.
//
// ES5 IMPLEMENTATION
//
function applyFilter(binary){
return function(a,b){
return binary(a,b);
}
}
function add(a,b){ return a + b; }
function mult(a,b){ return a * b }
// Examples:
applyFilter(add)(5,1) // -> 6
applyFilter(mult)(5,1) // -> 5
//
// ES6 IMPLEMENTATION
//
const applyFilter = (binary) => {
return (a,b) => {
return binary(a,b);
}
}
const add = (a,b) => { return a + b; }
const mult = (a,b) => { return a * b; }
// Examples:
applyFilter(add)(5,1) // -> 6
applyFilter(mult)(5,1) // -> 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment