FizzBuzz( without for loop) #3186
Closed
tuna7588
started this conversation in
Show and tell
Replies: 1 comment
-
Please mind that Codewars Github is not meant for help with general programming or learning questions. It's meant to discuss matters related to Codewars platform, the website, its functions, etc. To discuss interesting solutions and solving techniques, you can initiate a discussion under your solution on Codewars, or show it in I am going to close this discussion as off-topic for the Codewars Github. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys,
We just discuss about the FizzBuzz problem today in class and this is how we resolve it. I used to solve it with For loop, but today I use Map and forEach. I think this is just a great way to understand how these methods work. Here is the solution:
//getFunction
fizzBuzz = () => {
//getRangeOneToHundred
let array = new Array(100).fill(0).map((_, index) => index + 1);
//getTransformArray
let getTransformArray = array.map(number => {
if (number % 15 === 0) number = 'FizzBuzz';
if (number % 3 === 0) number = 'Fizz';
if (number % 5 === 0) number = 'Buzz';
return number;
});
//getOutput
return getTransformArray.forEach(number => console.log(number));
}
//print
fizzBuzz();
Beta Was this translation helpful? Give feedback.
All reactions