Last active
December 12, 2015 03:18
-
-
Save piscis/4705921 to your computer and use it in GitHub Desktop.
Power to the closures!
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
var a = []; for(var i=1; i<=100;i++) a.push((i*1)); | |
var stopWordAnalyzer = function(list){ | |
return function(stopword){ | |
var fizzCount = 0; | |
list.forEach(function(y){ if(stopword==y){fizzCount++;}}); | |
console.log('There are: '+fizzCount+' '+stopword+' in 1..100'); | |
} | |
} | |
b = stopWordAnalyzer(a.map(function(x,y){ | |
if(!(x%5) && !(x%3)) { return "FizzBuzz";} | |
else if(!(x%5)){ return "Buzz";} | |
else if(!(x%3)){ return "Fizz";} | |
else {return x}; | |
})); | |
['FizzBuzz','Buzz', 'Fizz'].forEach(b); | |
// Outputs: | |
>There are: 6 FizzBuzz in 1..100 | |
>There are: 14 Buzz in 1..100 | |
>There are: 27 Fizz in 1..100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment