Last active
May 12, 2016 11:14
-
-
Save choonkending/2d2b503c14c7eb23420143bf0115c2bb to your computer and use it in GitHub Desktop.
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 aAndB = ({ a, b }) => { | |
if (a && b) return 'A & B'; | |
return null; | |
}; | |
const onlyA = ({ a, b }) => { | |
if (a && !b) return 'Only A'; | |
return null; | |
}; | |
const onlyB = ({ a, b}) => { | |
if (!a && b) return 'Only B'; | |
return null; | |
}; | |
const empty = ({a, b}) => { | |
if (!a && !b) return 'Default'; | |
return null; | |
} | |
const props = { | |
a: 'a', | |
b: 'b' | |
}; | |
const strategies = [aAndB, onlyA, onlyB, empty]; | |
const result = strategies.map(fn => fn(props)).filter(el => el !== null)[0]; | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment