Created
September 30, 2019 20:50
-
-
Save Davidblkx/2e6470420fae88c3cb8b1ae7d79aa612 to your computer and use it in GitHub Desktop.
Simple FizzBuzz in typescript
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
console.log('A basic FizzBuzz in typescript') | |
const START_NUMBER = 1; | |
const LAST_NUMBER = 100; | |
const FIZZ = 'Fizz'; | |
const BUZZ = 'Buzz'; | |
function calcFizzBuzz(n: number): string | number { | |
let toPrint = ''; | |
if ((n % 3) === 0) { | |
toPrint = FIZZ | |
} | |
if ((n % 5) === 0) { | |
toPrint += BUZZ | |
} | |
return toPrint || n; | |
} | |
const result: (string | number)[] = []; | |
for (let i = START_NUMBER; i <= LAST_NUMBER; i++) { | |
result.push(calcFizzBuzz(i)) | |
} | |
result.forEach(n => console.warn(n)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment