diff --git a/modulo4/aprofundamento-typescript/.gitignore b/modulo4/aprofundamento-typescript/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/modulo4/aprofundamento-typescript/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/modulo4/aprofundamento-typescript/package-lock.json b/modulo4/aprofundamento-typescript/package-lock.json new file mode 100644 index 0000000..bbc7260 --- /dev/null +++ b/modulo4/aprofundamento-typescript/package-lock.json @@ -0,0 +1,35 @@ +{ + "name": "templateAPIsREST", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "templateAPIsREST", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "typescript": "^4.4.4" + } + }, + "node_modules/typescript": { + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz", + "integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, + "dependencies": { + "typescript": { + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz", + "integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==" + } + } +} diff --git a/modulo4/aprofundamento-typescript/package.json b/modulo4/aprofundamento-typescript/package.json new file mode 100644 index 0000000..e7973ff --- /dev/null +++ b/modulo4/aprofundamento-typescript/package.json @@ -0,0 +1,15 @@ +{ + "name": "templateAPIsREST", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node ./index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "typescript": "^4.4.4" + } +} diff --git a/modulo4/aprofundamento-typescript/src/exercicio1.ts b/modulo4/aprofundamento-typescript/src/exercicio1.ts new file mode 100644 index 0000000..f28f348 --- /dev/null +++ b/modulo4/aprofundamento-typescript/src/exercicio1.ts @@ -0,0 +1,24 @@ + +enum CORES { + VERMELHA = "vermelha", + LARANJA = "laranja", + AMARELA = "amarela", + VERDE = "verde", + AZUL = "azul", + ANIL = "anil", + VIOLETA = "violeta" +} + +type Pessoa = { + nome: string, + idade: number, + corFavorita: CORES +} + +const minhaPessoa: Pessoa = { + nome: "astrodev", + idade: 35, + corFavorita: CORES.VIOLETA +} + +console.log(minhaPessoa) \ No newline at end of file diff --git a/modulo4/aprofundamento-typescript/src/exercicio2.ts b/modulo4/aprofundamento-typescript/src/exercicio2.ts new file mode 100644 index 0000000..d080bb1 --- /dev/null +++ b/modulo4/aprofundamento-typescript/src/exercicio2.ts @@ -0,0 +1,28 @@ +type Estatisticas = { + maior: number, + menor: number, + media: number +} + +function obterEstatisticas(numeros: number[]): Estatisticas { + + const numerosOrdenados: number[] = numeros.sort( + (a, b) => a - b + ) + + let soma: number = 0 + + for (let num of numeros) { + soma += num + } + + const estatisticas: Estatisticas = { + maior: numerosOrdenados[numeros.length - 1], + menor: numerosOrdenados[0], + media: soma / numeros.length + } + + return estatisticas +} + +console.log(obterEstatisticas([1, 5, 6])) \ No newline at end of file diff --git a/modulo4/aprofundamento-typescript/src/exercicio3.ts b/modulo4/aprofundamento-typescript/src/exercicio3.ts new file mode 100644 index 0000000..a3f83f4 --- /dev/null +++ b/modulo4/aprofundamento-typescript/src/exercicio3.ts @@ -0,0 +1,37 @@ +type Post = { + autor: string, + texto: string +} + +const posts: Post[] = [ + { + autor: "Alvo Dumbledore", + texto: "Não vale a pena viver sonhando e se esquecer de viver" + }, + { + autor: "Severo Snape", + texto: "Menos 10 pontos para Grifinória!" + }, + { + autor: "Hermione Granger", + texto: "É levi-ô-sa, não levio-sá!" + }, + { + autor: "Dobby", + texto: "Dobby é um elfo livre!" + }, + { + autor: "Lord Voldemort", + texto: "Avada Kedavra!" + } +] + +function buscarPostsPorAutor(posts: Post[], autorInformado: string): Post[] { + return posts.filter( + (post) => { + return post.autor === autorInformado + } + ) +} + +console.log(buscarPostsPorAutor(posts, "Dobby")) \ No newline at end of file diff --git a/modulo4/aprofundamento-typescript/src/exercicio4.ts b/modulo4/aprofundamento-typescript/src/exercicio4.ts new file mode 100644 index 0000000..71069ee --- /dev/null +++ b/modulo4/aprofundamento-typescript/src/exercicio4.ts @@ -0,0 +1,23 @@ +type pokemon = { + name: string, + types: string, + healthPoints: number +} + +const pokemon1: pokemon = { + name: "Charmander", + types: "Fire", + healthPoints: 28 +} + +const pokemon2: pokemon = { + name: "Bulbasaur", + types: "Grass/Poison", + healthPoints: 31 +} + +const pokemon3: pokemon = { + name: "Squirtle", + types: "Water", + healthPoints: 35 +} \ No newline at end of file diff --git a/modulo4/aprofundamento-typescript/src/index.ts b/modulo4/aprofundamento-typescript/src/index.ts new file mode 100644 index 0000000..139597f --- /dev/null +++ b/modulo4/aprofundamento-typescript/src/index.ts @@ -0,0 +1,2 @@ + + diff --git a/modulo4/aprofundamento-typescript/tsconfig.json b/modulo4/aprofundamento-typescript/tsconfig.json new file mode 100644 index 0000000..e40c855 --- /dev/null +++ b/modulo4/aprofundamento-typescript/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es6", /* Specify ECMAScript target version */ + "module": "commonjs", /* Specify module code generation */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + "outDir": "./build", /* Redirect output structure to the directory. */ + "rootDir": "./src", /* Specify the root directory of input files. */ + "removeComments": true, /* Do not emit comments to output. */ + "noImplicitAny": true /* Raise error on declarations with an implied 'any' type. */ + } +} \ No newline at end of file