Created
December 2, 2017 18:05
-
-
Save ajchambeaud/6427a270cb4ef6f5d505e717c48a3a23 to your computer and use it in GitHub Desktop.
Revisions
-
ajchambeaud created this gist
Dec 2, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ /* * Write a program that prints the numbers from 1 to 100. * But for multiples of three print “Fizz” instead of the number * and for the multiples of five print “Buzz”. * For numbers which are multiples of both three and five print “FizzBuzz” */ const range = (init, end) => { const nums = []; for(let i = init; i <= end; i ++) { nums.push(i); } return nums; }; const multipleOf = (num, x) => x % num === 0; const printNumber = num => { if(multipleOf(3, num) && multipleOf(5, num)) return console.log("FizzBuzz"); if(multipleOf(5, num)) return console.log("Buzz"); if(multipleOf(3, num)) return console.log("Fizz"); console.log(num); } const nums = range(1, 100); nums.forEach(n => printNumber(n));