Here is my solution, I came up with a couple of solutions, but I will share this one as nobody has posted it. It's not the best approach, though. It's quite silly:
function fizzBuzz(number = 100) { let current = 1; let string = ''; while (current <= number) { string += current + ' '; current += 1; } string = string.trim() .replace(/[0-9]+/g, (match) => { const valueMap = ['FizzBuzz', match]; const index = match % 15; return valueMap[index] || match; }) .replace(/[0-9]+/g, (match) => { const valueMap = ['Fizz', match]; const index = match % 3; return valueMap[index] || match; }) .replace(/[0-9]+/g, (match) => { const valueMap = ['Buzz', match]; const index = match % 5; return valueMap[index] || match; }) return string.split(' '); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is my solution, I came up with a couple of solutions, but I will share this one as nobody has posted it. It's not the best approach, though. It's quite silly: