Code

console.log("Hello World");

/**
 * Calculates the nth Fibonacci number using recursion.
 * The sequence starts with fibonacci(1) = 1, fibonacci(2) = 2.
 * @param n - The position in the Fibonacci sequence (must be a positive integer).
 * @returns The nth Fibonacci number.
 */
function fibonacci(n: number): number {
  if (n === 1) return 1;
  if (n === 2) return 2;

  return fibonacci(n - 1) + fibonacci(n - 2);
}

console.log("Calculating Fibonacci numbers from 1 to 10:");
for (let i = 1; i <= 10; ++i) {
  console.log(`fibonacci(${i}) = ${fibonacci(i)}`);
}
{
  "name": "life-exe",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "build": "tsc",
    "start": "node build/index.js",
    "dev": "ts-node src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "typescript": "^5.8.3"
  }
}
{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "outDir": "./build",
    "rootDir": "./src"
  }
}

Last updated