Skip to content

Commit

Permalink
MÉTODO ATUALIZAR PROPRIEDADE
Browse files Browse the repository at this point in the history
  • Loading branch information
Ana-Carla-gif committed Sep 20, 2024
1 parent e62cc84 commit c6bfa70
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
50 changes: 25 additions & 25 deletions preProva.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
export function verificarParOuImpar(numero){
if(typeof numero != "number" ){
return null // o tipo precisa ser entre aspas
}
if(numero % 2 === 0){
return `Par`
export function verificarParOuImpar(numero) {
if (typeof numero != "number") {
return null; // o tipo precisa ser entre aspas
}
if (numero % 2 === 0) {
return `Par`;
} else {
return `Ímpar`;
}
}
export function maiorNumero(lista) {
// utiliza Array.isArray para verificar se uma variavél é uma lista
if (!Array.isArray(lista) || lista.length === 0) {
return null;
}
return Math.max(...lista);
}

export function atualizarPropriedade(objeto,propriedade,valor){ // in é como se estivesse dentro

} else{
return `Ímpar`
} }
export function maiorNumero(lista){ // utiliza Array.isArray para verificar se uma variavél é uma lista
if(!Array.isArray(lista) || lista.length === 0 ){
return null;
}
return Math.max (... lista);
}




// export function atualizarPropriedade(objeto,propriedade,valor){

// if(propriedade in objeto){
// objeto[propriedade] = valor
// }
// }
if(propriedade in objeto){
objeto[propriedade] = valor
return objeto
}return null
}

export function contarCaracter ()
30 changes: 15 additions & 15 deletions previa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
maiorNumero,
verificarParOuImpar,
//contarCaracter,
// atualizarPropriedade,
atualizarPropriedade,
} from "./preProva.js";

// Teste para a função maiorNumero
Expand Down Expand Up @@ -42,17 +42,17 @@ describe("verificarParOuImpar", () => {
// });
// });

// // Teste para a função atualizarPropriedade
// describe("atualizarPropriedade", () => {
// it("deve atualizar uma propriedade existente", () => {
// const objeto = { nome: "João", idade: 25 };
// expect(atualizarPropriedade(objeto, "idade", 30)).toEqual({
// nome: "João",
// idade: 30,
// });
// });
// it("deve retornar null se a propriedade não existir", () => {
// const objeto = { nome: "João" };
// expect(atualizarPropriedade(objeto, "altura", 1.8)).toBe(null);
// });
//});
// Teste para a função atualizarPropriedade
describe("atualizarPropriedade", () => {
it("deve atualizar uma propriedade existente", () => {
const objeto = { nome: "João", idade: 25 };
expect(atualizarPropriedade(objeto, "idade", 30)).toEqual({
nome: "João",
idade: 30,
});
});
it("deve retornar null se a propriedade não existir", () => {
const objeto = { nome: "João" };
expect(atualizarPropriedade(objeto, "altura", 1.8)).toBe(null);
});
});

0 comments on commit c6bfa70

Please sign in to comment.