Skip to content

Instantly share code, notes, and snippets.

@IgnusG
Last active November 6, 2019 13:43
Show Gist options
  • Save IgnusG/6f682a8c4b6f92dab5b02ff2418f5883 to your computer and use it in GitHub Desktop.
Save IgnusG/6f682a8c4b6f92dab5b02ff2418f5883 to your computer and use it in GitHub Desktop.
function isMultipleOf(x, say) {
return (i) => i % x == 0 ? say() : '';
}
const thenSay = (say) => () => say;
// The order matters. Any function with the signature (any)->(int)->str is valid
const whatShouldISayWhen = [
isMultipleOf(3, thenSay('Fizz')),
isMultipleOf(5, thenSay('Buzz'))
];
const until = 100;
for (let count = 1; count < until; count++) {
let saySomething = false;
const whatIWillSay = whatShouldISayWhen.map((is) => {
const iSay = is(count);
saySomething |= iSay != '';
return iSay;
});
if (saySomething) {
console.log(whatIWillSay.join(''));
} else {
console.log(count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment