FizzBuzz with TypeScript

This commit is contained in:
Oliver Davies 2022-09-24 00:49:23 +01:00
commit 4e2e0d6f0c
7 changed files with 2236 additions and 0 deletions

12
typescript/Dockerfile Normal file
View file

@ -0,0 +1,12 @@
FROM node:16-alpine
CMD ["sh"]
ENV PATH=${PATH}:/app/node_modules/.bin
RUN apk add --no-cache entr just
WORKDIR /app
USER node

2
typescript/fizzbuzz/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/*.js
/node_modules/

View file

@ -0,0 +1,23 @@
let FizzBuzz = require("./FizzBuzz");
it.each([
[1, "1"],
[2, "2"],
[4, "4"],
[7, "7"],
[8, "8"],
])("should return %s as '%s'", (input: number, expected: string) => {
expect(FizzBuzz(input)).toBe(expected);
});
it.each([3, 6, 9])("should return %s as 'Fizz'", (input: number) => {
expect(FizzBuzz(input)).toBe("Fizz");
});
it.each([5, 10, 20])("should return %s as 'Buzz'", (input: number) => {
expect(FizzBuzz(input)).toBe("Buzz");
});
it.each([15, 30, 45])("should return %s as 'FizzBuzz'", (input: number) => {
expect(FizzBuzz(input)).toBe("FizzBuzz");
});

View file

@ -0,0 +1,15 @@
module.exports = (input: number): string => {
if (input % 3 == 0 && input % 5 == 0) {
return "FizzBuzz";
}
if (input % 3 == 0) {
return "Fizz";
}
if (input % 5 == 0) {
return "Buzz";
}
return input.toString();
};

View file

@ -0,0 +1,14 @@
default:
just --list
clean:
rm *.js -f
compile: clean
tsc *.ts
test: compile
jest *.test.js
test-watch:
ls *.ts | entr -r just test

View file

@ -0,0 +1,11 @@
{
"devDependencies": {
"@types/jest": "^29.0.3",
"jest": "^29.0.3",
"prettier": "^2.7.1"
},
"dependencies": {
"tsc": "^2.0.4",
"typescript": "^4.8.3"
}
}

File diff suppressed because it is too large Load diff