Skip to content

Instantly share code, notes, and snippets.

@choonkending
Last active May 12, 2016 11:14
Show Gist options
  • Save choonkending/2d2b503c14c7eb23420143bf0115c2bb to your computer and use it in GitHub Desktop.
Save choonkending/2d2b503c14c7eb23420143bf0115c2bb to your computer and use it in GitHub Desktop.
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