Created
March 5, 2021 17:58
-
-
Save indifferentghost/1a799b401bd0ee8f262eb788ed4112fc to your computer and use it in GitHub Desktop.
Fizzbuzz Without If JavaScript
This file contains 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
function replacer(arr, num, replace) { | |
for (let i = num - 1; i < arr.length; i += num) { | |
arr[i] = replace; | |
} | |
} | |
function fizzBuzz(n) { | |
const arr = Array.from({ length: n }, (_, i) => i + 1); | |
replacer(arr, 3, 'foo'); | |
replacer(arr, 5, 'bar'); | |
replacer(arr, 15, 'foobar'); | |
return arr; | |
} | |
fizzBuzz(100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment