Skip to content

Instantly share code, notes, and snippets.

@mathieueveillard
Last active October 8, 2021 09:55
Show Gist options
  • Save mathieueveillard/65301ed3e0144d52282fbcead914dffd to your computer and use it in GitHub Desktop.
Save mathieueveillard/65301ed3e0144d52282fbcead914dffd to your computer and use it in GitHub Desktop.
const isMultipleOf = (m: number) => (n: number): boolean => n % m === 0;
export function internal(n: number): string {
let result = "";
if (isMultipleOf(3)(n)) {
result += "Fizz";
}
if (isMultipleOf(5)(n)) {
result += "Buzz";
}
return result || n.toString();
}
export function FizzBuzz(n: number): string[] {
return [...Array(n)].map((_, i) => i + 1).map(internal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment