Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modulo7/recursividade/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
node_modules
37 changes: 37 additions & 0 deletions modulo7/recursividade/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions modulo7/recursividade/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
13 changes: 13 additions & 0 deletions modulo7/recursividade/src/exercicio01.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}
7 changes: 7 additions & 0 deletions modulo7/recursividade/src/exercício02.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const sum = (n: number): number => {
if (n <= 0) {
return 0
}

return n + sum(n - 1)
}
8 changes: 8 additions & 0 deletions modulo7/recursividade/src/exercício03.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const sumLoop = (n: number): number => {
let sum = 0
for (n; n >= 0; n--) {
sum += n
}

return sum
}
6 changes: 6 additions & 0 deletions modulo7/recursividade/src/exercício04.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const printArray = (arr: Array<any>, index: number = 0): void => {
if (index < arr.length) {
console.log(arr[index])
printArray(arr, index + 1)
}
}
21 changes: 21 additions & 0 deletions modulo7/recursividade/src/index.ts
Original file line number Diff line number Diff line change
@@ -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"])
11 changes: 11 additions & 0 deletions modulo7/recursividade/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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. */
}
}