Created
July 13, 2021 14:12
-
-
Save AlenVelocity/b6207c0678397135863023aeedcba88c to your computer and use it in GitHub Desktop.
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
type Filter<T> = { | |
[K in keyof T as Exclude<K, 'run' | 'set'>]: T[K] | |
} | |
class FizzBuzz { | |
constructor(public max: number = 100, public fizz: number = 3, public buzz: number = 5) { | |
} | |
set = (key: keyof Filter<FizzBuzz>, num: number) => { | |
this[key] = num | |
return this | |
} | |
run = () => { | |
let out = '' | |
for (let i = 1; i <= this.max; i++) { | |
let temp = '' | |
temp += Number.isInteger(i/this.fizz) ? 'fizz' : '' | |
temp += Number.isInteger(i/this.buzz) ? 'buzz' : '' | |
out += temp? `${temp}\n` : `${i}\n` | |
} | |
return out | |
} | |
} | |
console.log(new FizzBuzz(100, 3, 5).run()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment