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
20 changes: 20 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/.codesandbox/workspace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"responsive-preview": {
"Mobile": [
320,
675
],
"Tablet": [
1024,
765
],
"Desktop": [
1400,
800
],
"Desktop HD": [
1920,
1080
]
}
}
15 changes: 15 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
</head>

<body>
<div id="app"></div>

<script src="src/index.ts">
</script>
</body>

</html>
22 changes: 22 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "recursividade",
"version": "1.0.0",
"description": "",
"main": "index.html",
"scripts": {
"start": "parcel index.html --open",
"build": "parcel build index.html"
},
"dependencies": {
"@types/jest": "28.1.6",
"jest": "28.1.3",
"parcel-bundler": "^1.6.1"
},
"devDependencies": {
"typescript": "4.4.4"
},
"resolutions": {
"@babel/preset-env": "7.13.8"
},
"keywords": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { checkEmptyObject } from "./checkEmptyObject";

test("checkEmptyObject", () => {
expect(checkEmptyObject({ prop1: "maçã", prop2: "bananinha" })).toBe(false);
expect(checkEmptyObject({ prop1: undefined, prop2: "bananinha" })).toBe(true);
expect(checkEmptyObject({ prop1: null, prop2: "bananinha" })).toBe(true);
expect(checkEmptyObject({ prop1: 0, prop2: "bananinha" })).toBe(true);
expect(checkEmptyObject({ prop1: "", prop2: "bananinha" })).toBe(true);
expect(checkEmptyObject({ prop1: [], prop2: "bananinha" })).toBe(true);
expect(checkEmptyObject({ prop1: {}, prop2: "bananinha" })).toBe(true);
expect(
checkEmptyObject({
prop1: {
outraProp: {
a: {
b: null
}
}
},
prop2: "bananinha"
})
).toBe(true);
});
30 changes: 30 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/src/checkEmptyObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function isEmpty(value: any): boolean {
return (
value === undefined ||
value === null ||
value === 0 ||
value === "" ||
(Array.isArray(value) && value.length === 0) ||
(typeof value === "object" &&
(Object.values(value!).length === 0 || checkEmptyObject(value)))
);
}

export function checkEmptyObject(obj: any): boolean {
// exemplo:
// const obj = {
// name: "nome",
// id: "Id",
// number: 5
// }

const values = Object.values(obj);
// exemplo array values
// ["nome", "id", 5]
for (let value of values) {
if (isEmpty(value)) {
return true;
}
}
return false;
}
10 changes: 10 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/src/factorial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const factorial = (n: number): number => {
if (n <= 0) {
return 1;
}

return n * factorial(n - 1);
// exmplo com n=2 => 2* 1 *1
// exmplo com n=3 => 3* 2* 1 *1
// exmplo com n=4 => 4* 3* 2* 1 *1
};
7 changes: 7 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/src/fibonacci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const fibonacci = (n: number): number => {
if (n <= 2) {
return 1;
}

return fibonacci(n - 1) + fibonacci(n - 2);
};
26 changes: 26 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { fibonacci } from "./fibonacci";
import { factorial } from "./factorial";
import { printCharacters } from "./printCharacters";
import { checkEmptyObject } from "./checkEmptyObject";

// console.log("factorial:");
// console.log("1", factorial(1));
// console.log("2", factorial(2));
// console.log("3", factorial(3));
// console.log("4", factorial(4));
// console.log("5", factorial(5));
// console.log("6", factorial(6));

//console.log("fibonacci:");
// console.log("1", fibonacci(1));
// console.log("2", fibonacci(2));
// console.log("3", fibonacci(3));
// console.log("4", fibonacci(4));
// console.log("5", fibonacci(5));
// console.log("6", fibonacci(6));
//console.log("Count", fibonacci(7));

// console.log("printCharacters:");
// console.log("Olá", printCharacters("Olá"));
// console.log("tudo", printCharacters("tudo"));
// console.log("bem?", printCharacters("bem?"));
10 changes: 10 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/src/printCharacters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const printCharacters = (str: string, index: number = 0): void => {
// if (index < str.length) {
// console.log(str[index]);
// printCharacters(str, index + 1);
// }

for (let char of str) {
console.log(char);
}
};
16 changes: 16 additions & 0 deletions Back-end/modulo2/MODULO3/recursividade/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"strict": true,
"module": "commonjs",
"jsx": "preserve",
"esModuleInterop": true,
"sourceMap": true,
"allowJs": true,
"lib": [
"es2017",
"dom"
],
"rootDir": "src",
"moduleResolution": "node"
}
}