Skip to content

Instantly share code, notes, and snippets.

@piscis
Last active December 12, 2015 03:18
Show Gist options
  • Save piscis/4705921 to your computer and use it in GitHub Desktop.
Save piscis/4705921 to your computer and use it in GitHub Desktop.
Power to the closures!
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