Skip to content

typescript-I #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"homepage": "https://github.com/labenuexercicios/typescript-I-template#readme",
"devDependencies": {
"@types/node": "^20.5.7",
"typescript": "^4.9.4"
}
}
}
6 changes: 3 additions & 3 deletions src/fixacao/exercicio1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Com essa informação, a função retorna se o triângulo é equilátero, isósc
Refatore a função para o Typescript.
*/

/* DESCOMENTE ESTA FUNÇÃO
function checaTriangulo(a, b, c) {
// DESCOMENTE ESTA FUNÇÃO
function checaTriangulo(a:number, b:number, c:number):string {
if ((a !== b) && (b !== c)) {
return 'Escaleno'
} else if (a === b && b === c) {
Expand All @@ -18,4 +18,4 @@ function checaTriangulo(a, b, c) {
console.log(checaTriangulo(7, 7, 7))
console.log(checaTriangulo(7, 7, 9))
console.log(checaTriangulo(7, 8, 9))
*/

5 changes: 2 additions & 3 deletions src/fixacao/exercicio2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Não são bissextos todos os demais anos.
Com isso em mente, refatore a função para o Typescript.
*/

/* DESCOMENTE ESTA FUNÇÃO
function checaAnoBissexto(ano) {
// DESCOMENTE ESTA FUNÇÃO
function checaAnoBissexto(ano: number):boolean {
const cond1 = ano % 400 === 0
const cond2 = (ano % 4 === 0) && (ano % 100 !== 0)

Expand All @@ -18,4 +18,3 @@ function checaAnoBissexto(ano) {

console.log(checaAnoBissexto(2022))
console.log(checaAnoBissexto(2020))
*/
7 changes: 3 additions & 4 deletions src/fixacao/exercicio3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ A função abaixo pergunta à pessoa suas três cores favoritas e imprime no con
Refatore a função para o Typescript.
*/

/* DESCOMENTE ESTA FUNÇÃO
function imprimeTresCoresFavoritas() {
// DESCOMENTE ESTA FUNÇÃO
function imprimeTresCoresFavoritas():void {
const cor1 = process.argv[2]
const cor2 = process.argv[3]
const cor3 = process.argv[4]

console.log([cor1, cor2, cor3])
}

imprimeTresCoresFavoritas()
*/
imprimeTresCoresFavoritas()
8 changes: 7 additions & 1 deletion src/tipando/frota.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export const frota: {}[] = [
export type TCarro = {
marca: string,
modelo: string,
ano: number,
}

export const frota: TCarro[] = [
{
marca: 'Chevrolet',
modelo: 'Onix',
Expand Down
8 changes: 6 additions & 2 deletions src/tipando/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function buscarCarrosPorMarca(frota, marca) {
import {TCarro, frota} from "./frota";

function buscarCarrosPorMarca(frota:TCarro[], marca:string):TCarro[]{
if (marca === undefined) {
return frota
}
Expand All @@ -8,4 +10,6 @@ function buscarCarrosPorMarca(frota, marca) {
return carro.marca === marca
}
)
}
}

console.table(buscarCarrosPorMarca(frota, 'Ford'),);