Last active
November 6, 2019 13:43
-
-
Save IgnusG/6f682a8c4b6f92dab5b02ff2418f5883 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
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