Skip to content

Instantly share code, notes, and snippets.

@ryenbeatty
Last active November 20, 2015 03:34
Show Gist options
  • Select an option

  • Save ryenbeatty/7cec7b235c938d0aef16 to your computer and use it in GitHub Desktop.

Select an option

Save ryenbeatty/7cec7b235c938d0aef16 to your computer and use it in GitHub Desktop.
// 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)
@ryenbeatty
Copy link
Author

For shits ang giggles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment