Skip to content

Instantly share code, notes, and snippets.

@grommett
Created September 20, 2016 04:21
Show Gist options
  • Save grommett/d19cd290b8ce4f38f66dace4ef66578b to your computer and use it in GitHub Desktop.
Save grommett/d19cd290b8ce4f38f66dace4ef66578b to your computer and use it in GitHub Desktop.
Conditional
//
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