Skip to content

Instantly share code, notes, and snippets.

@indifferentghost
Created March 5, 2021 17:58
Show Gist options
  • Save indifferentghost/1a799b401bd0ee8f262eb788ed4112fc to your computer and use it in GitHub Desktop.
Save indifferentghost/1a799b401bd0ee8f262eb788ed4112fc to your computer and use it in GitHub Desktop.
Fizzbuzz Without If JavaScript
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