Write a function that:
- returns "Fizz" for multiples of 3
- returns "Buzz" for multiples of 5
- returns "FizzBuzz" for multiples of both 3 and 5
Any other number should return the number as string.
export function fizzBuzz(input: number): string {
const output: string = `${input % 3 === 0 ? "Fizz" : ""}${input % 5 === 0 ? "Buzz" : ""}`;
return output.length > 0 ? output : input.toString(10);
}
/// <reference path="/runner/typings/mocha/index.d.ts" />
/// <reference path="/runner/typings/chai/index.d.ts" />
import solution = require('./solution');
import { assert } from "chai";
describe("solution", () => {
it("Divisible By Three", () => {
assert.equal(solution.fizzBuzz(3), "Fizz");
assert.equal(solution.fizzBuzz(12), "Fizz");
})
it("Divisible By Five", () => {
assert.equal(solution.fizzBuzz(5), "Buzz");
assert.equal(solution.fizzBuzz(95), "Buzz");
})
it("Divisible By Three And Five", () => {
assert.equal(solution.fizzBuzz(15), "FizzBuzz");
assert.equal(solution.fizzBuzz(90), "FizzBuzz");
})
it("Not Divisible By Three Or Five", () => {
assert.equal(solution.fizzBuzz(1), "1");
assert.equal(solution.fizzBuzz(7), "7");
});
});