diff --git a/modulo7/recursividade/.gitignore b/modulo7/recursividade/.gitignore new file mode 100644 index 0000000..48912d2 --- /dev/null +++ b/modulo7/recursividade/.gitignore @@ -0,0 +1,2 @@ +build +node_modules \ No newline at end of file diff --git a/modulo7/recursividade/package-lock.json b/modulo7/recursividade/package-lock.json new file mode 100644 index 0000000..e4a9d69 --- /dev/null +++ b/modulo7/recursividade/package-lock.json @@ -0,0 +1,37 @@ +{ + "name": "recursividade", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "recursividade", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "typescript": "^5.0.3" + } + }, + "node_modules/typescript": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.3.tgz", + "integrity": "sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=12.20" + } + } + }, + "dependencies": { + "typescript": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.3.tgz", + "integrity": "sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==", + "dev": true + } + } +} diff --git a/modulo7/recursividade/package.json b/modulo7/recursividade/package.json new file mode 100644 index 0000000..4a0a464 --- /dev/null +++ b/modulo7/recursividade/package.json @@ -0,0 +1,15 @@ +{ + "name": "recursividade", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "tsc && node ./build/index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "typescript": "^5.0.3" + } +} diff --git a/modulo7/recursividade/src/exercicio01.ts b/modulo7/recursividade/src/exercicio01.ts new file mode 100644 index 0000000..9580346 --- /dev/null +++ b/modulo7/recursividade/src/exercicio01.ts @@ -0,0 +1,13 @@ +export const printAsc = (n: number): void => { + if (n >= 0) { + printAsc(n - 1) + console.log(n) + } +} + +export const printDesc = (n: number): void => { + if (n >= 0) { + console.log(n) + printDesc(n - 1) + } +} \ No newline at end of file diff --git "a/modulo7/recursividade/src/exerc\303\255cio02.ts" "b/modulo7/recursividade/src/exerc\303\255cio02.ts" new file mode 100644 index 0000000..4dc598e --- /dev/null +++ "b/modulo7/recursividade/src/exerc\303\255cio02.ts" @@ -0,0 +1,7 @@ +export const sum = (n: number): number => { + if (n <= 0) { + return 0 + } + + return n + sum(n - 1) +} \ No newline at end of file diff --git "a/modulo7/recursividade/src/exerc\303\255cio03.ts" "b/modulo7/recursividade/src/exerc\303\255cio03.ts" new file mode 100644 index 0000000..c2646b8 --- /dev/null +++ "b/modulo7/recursividade/src/exerc\303\255cio03.ts" @@ -0,0 +1,8 @@ +export const sumLoop = (n: number): number => { + let sum = 0 + for (n; n >= 0; n--) { + sum += n + } + + return sum +} \ No newline at end of file diff --git "a/modulo7/recursividade/src/exerc\303\255cio04.ts" "b/modulo7/recursividade/src/exerc\303\255cio04.ts" new file mode 100644 index 0000000..4b9389e --- /dev/null +++ "b/modulo7/recursividade/src/exerc\303\255cio04.ts" @@ -0,0 +1,6 @@ +export const printArray = (arr: Array, index: number = 0): void => { + if (index < arr.length) { + console.log(arr[index]) + printArray(arr, index + 1) + } +} \ No newline at end of file diff --git a/modulo7/recursividade/src/index.ts b/modulo7/recursividade/src/index.ts new file mode 100644 index 0000000..b58f913 --- /dev/null +++ b/modulo7/recursividade/src/index.ts @@ -0,0 +1,21 @@ +import { printAsc, printDesc } from "./exercicio01"; +import { sum } from "./exercício02"; +import { sumLoop } from "./exercício03"; +import { printArray } from "./exercício04"; + +console.log("Exercício 01 a:") +printAsc(5) +console.log("Exercício 01 b:") +printDesc(5) + +console.log("Exercício 02:") +console.log(sum(10)) +console.log(sum(4)) + +console.log("Exercício 03:") +console.log(sumLoop(10)) +console.log(sumLoop(4)) + +console.log("Exercício 04:") +printArray([10, 20, 30, 40, 50]) +printArray(["Banana", "Morango", "Melancia"]) diff --git a/modulo7/recursividade/tsconfig.json b/modulo7/recursividade/tsconfig.json new file mode 100644 index 0000000..a9ee948 --- /dev/null +++ b/modulo7/recursividade/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, + "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, + "outDir": "./build" /* Redirect output structure to the directory. */, + "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, + "strict": true /* Enable all strict type-checking options. */, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} \ No newline at end of file