Last active
November 20, 2015 03:34
-
-
Save ryenbeatty/7cec7b235c938d0aef16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // range :: Number -> Number -> [Number] | |
| function range(from, to) { | |
| var result = []; | |
| while (from < to) { | |
| result.push(from); | |
| from += 1; | |
| } | |
| return result; | |
| } | |
| var array = range(1, 100) | |
| // isFizz :: Number -> Bool | |
| var isFizz = function(x) { return x % 3 === 0 } | |
| // isBuzz :: Number -> Bool | |
| var isBuzz = function(x) { return x % 5 === 0 } | |
| // isFizzBuzz :: Number -> Bool | |
| var isFizzBuzz = function(x) { return x % 3 === 0 && x % 5 === 0 } | |
| // getType | |
| var getType = function(x) { | |
| return isFizzBuzz(x) ? 'FizzBuzz' : isFizz(x) ? 'Fizz' : isBuzz(x) ? 'Buzz' : x | |
| } | |
| // fizzBuzz | |
| var fizzBuzz = array.map(function(num) { return getType(num) }) | |
| console.log(fizzBuzz) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For shits ang giggles.