Created
February 11, 2025 06:32
-
-
Save dominicstop/dc165b14730a0a8f5c4735e287eac199 to your computer and use it in GitHub Desktop.
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 characters
| function fizzBuzz(n: number): string[] { | |
| let results: Array<string> = []; | |
| for(let i = 1; i <= n; i++){ | |
| if((i % 3 == 0) && (i % 5 == 0)){ | |
| results.push("FizzBuzz"); | |
| } else if(i % 3 == 0) { | |
| results.push("Fizz"); | |
| } else if(i % 5 == 0) { | |
| results.push("Buzz"); | |
| } else { | |
| results.push(`${i}`); | |
| }; | |
| }; | |
| return results; | |
| }; | |
| let inputs = [3, 5, 15]; | |
| for(let i = 0; i < inputs.length; i++){ | |
| const input = inputs[i]; | |
| const result = fizzBuzz(input); | |
| console.log(result); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment