Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. function fizzBuzz() {
  2. // Generate an array with 100 undefined items
  3. // iterate over array and build string of fizzbuzzes
  4. // alternately, use .forEach and log result each iteration
  5. const fizzBuzzResult = Array.apply(null, { length: 100 })
  6. .reduce( (accumulator, elem, i) => {
  7. let result = "";
  8. if ((i % 3) === 0) result += "Fizz"
  9. if ((i % 5) === 0) result += "Buzz";
  10. if (result !== "") accumulator += `${i}: ${result}!\n`;
  11. return accumulator;
  12. }, "");
  13.  
  14. console.log(fizzBuzzResult);
  15. }
  16.  
  17. fizzBuzz();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement