FizzBuzz with TypeScript
This commit is contained in:
commit
4e2e0d6f0c
12
typescript/Dockerfile
Normal file
12
typescript/Dockerfile
Normal 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
2
typescript/fizzbuzz/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*.js
|
||||||
|
/node_modules/
|
23
typescript/fizzbuzz/FizzBuzz.test.ts
Normal file
23
typescript/fizzbuzz/FizzBuzz.test.ts
Normal 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");
|
||||||
|
});
|
15
typescript/fizzbuzz/FizzBuzz.ts
Normal file
15
typescript/fizzbuzz/FizzBuzz.ts
Normal 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();
|
||||||
|
};
|
14
typescript/fizzbuzz/justfile
Normal file
14
typescript/fizzbuzz/justfile
Normal 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
|
11
typescript/fizzbuzz/package.json
Normal file
11
typescript/fizzbuzz/package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
2159
typescript/fizzbuzz/yarn.lock
Normal file
2159
typescript/fizzbuzz/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue