3 ms·
The code being hard to read may be partly a consequence of having to bend over backwards to fulfill the absurd requirements. No numerical operations on a fizzb
by lou1306 2y ago
The code being hard to read may be partly a consequence of having to bend over backwards to fulfill the absurd requirements.
No numerical operations on a fizzbuzz problem? Give me a damn break.
- Ukv 2y agoI feel the no-numbers requirement essentially just boils down to replacing `num % 5 == 0` with `num.endswith(('0', '5', 'A'))` - or at least that's what I went with while playing along. Most of the complication (after the author realized they should use base-15) seems self-inflicted from the choice to write it within the type system, which the interviewer advised against. Fully granted that I'm not familiar with TypeScript, but I find it hard to believe that code like the below is more readable to anyone than the equivalent `for num in nums` loop. type FizzBuzz<T> = T extends `${_}${_|""}${_|""}` ? `${Fizzer<T>}${Bazzer<T>}${Buzzer<T>}` : ""; type Folded<T> = T extends [infer Head, ...infer Tail] ? `${FizzBuzz<Head>}${Folded<Tail>}` : "";