Created
September 20, 2016 04:21
-
-
Save grommett/d19cd290b8ce4f38f66dace4ef66578b to your computer and use it in GitHub Desktop.
Conditional
This file contains 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
// | |
const condition = (...args) => (val) => { | |
let result = args.filter((pair) => { | |
if(pair[0] === val) return true; | |
return false; | |
}) | |
return result.length !==0 ? result[0][1] : undefined; | |
} | |
const numCondition = condition( | |
[0, 100*2], | |
[100, 'it was a 100'], | |
[1000, 'it was 1000'] | |
); | |
console.log('zero returns ', numCondition(0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment