Learn how to think in programming terms using TypeScript to solve logic exercises.
This project uses Bun as a runtime, you must install it in order to run the project.
The module bun:test is used to write tests,
to run any TypeScript file you must run:
bun test ./src/<FILENAME>.tsTest Driven Development is a great way to get started with writing code.
- You must provide test for the expected outputs, consider the following exercise:
Write a program that prints the multiplication table of a number N.
- You must write the test first, consider the following test:
it('should return the multiplication table of 2', () => {
const expected = '2 x 1 = 2\n2 x 2 = 4\n2 x 3 = 6\n2 x 4 = 8\n2 x 5 = 10\n2 x 6 = 12\n2 x 7 = 14\n2 x 8 = 16\n2 x 9 = 18\n2 x 10 = 20\n';
const result = multiplicationTable(2);
expect(result).toBe(expected);
});- Write the code that makes the test pass:
function multiplicationTable(n: number): string {
let table = '';
for (let i = 1; i <= 10; i++) {
table += `${n} x ${i} = ${n * i}\n`;
}
return table;
}- Run the test:
bun test ./src/multiplicationTable.tsThe goal of this repository is to use TypeScript to solve logic exercises from the following sources:
- Geeks4Geeks: https://www.geeksforgeeks.org/logic-building-problems/
- Universidad Santa Maria: https://progra-utfsm.github.io/material/01_Intro_Programacion.html