Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions Prof - Claude IA/JavaScript/contar-ocorrencias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function contarOcorrencias(array, n){
let contador = 0;

for (let i = 0; i < array.length; i++){
if (array[i] === n){
contador++
}
}

return contador;

}

console.log(contarOcorrencias([1, 2, 3, 2, 4, 2], 2));
// Retorna: 3

console.log(contarOcorrencias(["oi", "tchau", "oi", "oi"], "oi"));
// Retorna: 3
15 changes: 15 additions & 0 deletions Prof - Claude IA/JavaScript/contar-vogais.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function contarVogais(palavra){
let arrayPalavra = palavra.split("")
let contador = 0;

for (let i = 0; i < arrayPalavra.length; i++){
if (arrayPalavra[i] === "a" || arrayPalavra[i] === "e" || arrayPalavra[i] === "i" || arrayPalavra[i] === "o" || arrayPalavra[i] === "u") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function only counts lowercase vowels, misses uppercase

Low Severity

The contarVogais function only checks for lowercase vowels (a, e, i, o, u) and ignores uppercase vowels (A, E, I, O, U). This causes incorrect counts when input contains uppercase letters. For example, contarVogais("JavaScript") would return 2 instead of 3 because the capital A is missed, and contarVogais("HELLO") would return 0 instead of 2.

Fix in Cursor Fix in Web

contador++;
}
}

return contador;
}

console.log(contarVogais("javascript"));
console.log(contarVogais("programacao"));
13 changes: 13 additions & 0 deletions Prof - Claude IA/JavaScript/copiar-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function copiarArray(array) {

let copia = [];

for (let i = 0; i < array.length; i++){
copia.push(array[i]);
}

return copia;
}


console.log(copiarArray([1, 2, 3]))
11 changes: 11 additions & 0 deletions Prof - Claude IA/JavaScript/criar-array_array_function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function criarArray(n){
let array = [];

for (let i = 1; i <= n; i++){
array.push(i);
}

return array;
}

console.log(criarArray(5));
8 changes: 8 additions & 0 deletions Prof - Claude IA/JavaScript/dobrar-valores.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let num = [2, 4, 6, 8];
let dob = [];

for (let i = 0; i < num.length; i++){
dob.push(num[i] * 2)
}

console.log(dob)
12 changes: 12 additions & 0 deletions Prof - Claude IA/JavaScript/inverter-array-manualmente.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function inverterArray(array){
let invertido = [];

for (let i = array.length - 1; i >= 0; i--){
invertido.push(array[i])
}

return invertido
}


console.log(inverterArray([1, 2, 3, 4, 5]));
19 changes: 19 additions & 0 deletions Prof - Claude IA/JavaScript/maior-menor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function maiorMenor(array){
let maior = array[0];
let menor = array[0];

for (let i = 0; i < array.length; i++){
if (array[i] > maior){
maior = array[i];
}

if (array[i] < menor){
menor = array[i];
}
}

return { maior: maior, menor: menor };
}

console.log(maiorMenor([5, 2, 9, 1, 7]));
// Retorna: { maior: 9, menor: 1 } ✅
13 changes: 13 additions & 0 deletions Prof - Claude IA/JavaScript/maior-que-n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function maioresQue(array, n){
let numM = [];

for (let i = 0; i < array.length; i++){
if (array[i] > n){
numM.push(array[i])
}
}

return numM;
}

console.log(maioresQue([1, 2, 3, 4, 5], 3));
17 changes: 17 additions & 0 deletions Prof - Claude IA/JavaScript/media-pares.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function mediaPares(array){
let soma = 0;
let contador = 0;

for (let i = 0; i < array.length; i++){
if (array[i] % 2 === 0){
soma += array[i];
contador++;
}
}

let media = soma / contador;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero returns NaN for odd-only arrays

Low Severity

When the input array contains no even numbers, contador remains 0, and the division soma / contador evaluates to NaN (0 divided by 0). For instance, calling mediaPares([1, 3, 5]) returns NaN rather than a meaningful result like 0 or an indication that no even numbers exist.

Fix in Cursor Fix in Web


return media;
}

console.log(mediaPares([1, 2, 3, 4, 5, 6]));
18 changes: 18 additions & 0 deletions Prof - Claude IA/JavaScript/numero-entre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function numeroEntre(array, min, max){
let minMax = [];

for(let i = 0; i < array.length; i++){
if(array[i] >= min && array[i] <= max){
minMax.push(array[i])
}
}

return minMax
}


console.log(numeroEntre([1, 5, 10, 15, 20, 25], 10, 20));
// Retorna: [10, 15, 20]

console.log(numeroEntre([3, 7, 12, 18, 25], 5, 15));
// Retorna: [7, 12]
12 changes: 12 additions & 0 deletions Prof - Claude IA/JavaScript/numeros-negativos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function testeA (array){
let b = [];

for (let i = 0; i < array.length; i++){
if (array[i] < 0){
b.push(array[i])
}
}

return b
}
console.log(testeA([5, -3, 8, -1, 10, -5, 2]))
18 changes: 18 additions & 0 deletions Prof - Claude IA/JavaScript/pares-impares-separados.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function separarParImpar(array){
let pares = []
let impares = []

for (let i = 0; i < array.length; i++){
if (array[i] % 2 === 0){
pares.push(array[i])
} else {
impares.push(array[i])
}
}

return {pares: pares, impares: impares}
}


console.log(separarParImpar([1, 2, 3, 4, 5, 6]));
// Retorna: { pares: [2, 4, 6], impares: [1, 3, 5] }
12 changes: 12 additions & 0 deletions Prof - Claude IA/JavaScript/primeiro-N-elementos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function primeirosN(array, n){
let primeiros = [];

for(let i = 0; i < n; i++){
primeiros.push(array[i]);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loop boundary allows out-of-bounds array access

Low Severity

The primeirosN function's loop iterates up to n without checking if n exceeds the array length. When n > array.length, the loop accesses indices beyond the array bounds, causing undefined values to be pushed into the result. For example, primeirosN([1, 2], 5) returns [1, 2, undefined, undefined, undefined] instead of just [1, 2]. The loop condition could use Math.min(n, array.length) to prevent this.

Fix in Cursor Fix in Web


return primeiros;
}

console.log(primeirosN([1, 2, 3, 4, 5], 3));
console.log(primeirosN(["a", "b", "c", "d"], 2));
18 changes: 18 additions & 0 deletions Prof - Claude IA/JavaScript/remover-valores-especificos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function removerValor (array, n){
let corretos = [];

for (let i = 0; i < array.length; i++){
if (array[i] !== n){
corretos.push(array[i])
}
}

return corretos
}


console.log(removerValor([1, 2, 3, 2, 4, 2, 5], 2));
// Retorna: [1, 3, 4, 5]

console.log(removerValor(["a", "b", "c", "b"], "b"));
// Retorna: ["a", "c"]
20 changes: 20 additions & 0 deletions Prof - Claude IA/JavaScript/soma-acumulada.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function somaAcumulada (array){
let soma = 0;
let resultado = [];

for (let i = 0; i < array.length; i++){
soma += array[i];
resultado.push(soma)
}

return resultado
}


console.log(somaAcumulada([1, 2, 3, 4]));
// [1, 1+2=3, 1+2+3=6, 1+2+3+4=10]
// Retorna: [1, 3, 6, 10]

console.log(somaAcumulada([5, 10, 15]));
// [5, 5+10=15, 5+10+15=30]
// Retorna: [5, 15, 30]
22 changes: 22 additions & 0 deletions Prof - Claude IA/JavaScript/substituir-valores.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function substituir (array, valorAntigo, valorNovo){
let novo = [];

for(let i = 0; i < array.length; i++){
if (array[i] !== valorAntigo){
novo.push(array[i])
} else if (array[i] === valorAntigo){
novo.push(valorNovo)
}
}

return novo
}




console.log(substituir([1, 2, 3, 2, 4], 2, 99));
// Retorna: [1, 99, 3, 99, 4]

console.log(substituir(["a", "b", "c", "b"], "b", "z"));
// Retorna: ["a", "z", "c", "z"]
10 changes: 10 additions & 0 deletions Prof - Claude IA/JavaScript/todos-positivos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function todosPositivos(array){
for (let i = 0; i < array.length; i++){
if (array[i] <= 0){
return false;
}
}
return true;
}

console.log(todosPositivos([1, 2, 3, 4])); // true ✅
11 changes: 11 additions & 0 deletions Prof - Claude IA/JavaScript/verificiar-existencia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function contemElemento(array, elemento){
for (let i = 0; i < array.length; i++) {
if (array[i] === elemento) {
return true;
}
}
return false;
}

console.log(contemElemento([10, 20, 30], 20));
console.log(contemElemento([10, 20, 30], 99));