Skip to content

Instantly share code, notes, and snippets.

@raulmangolin
Last active August 1, 2019 14:31
Show Gist options
  • Save raulmangolin/29ab007a06513449372e5eb7037ba1ba to your computer and use it in GitHub Desktop.
Save raulmangolin/29ab007a06513449372e5eb7037ba1ba to your computer and use it in GitHub Desktop.
Exercícios Java Escrito
function produto(numeros) {
let resultado = numeros[0];
for (let i = 1; i < numeros.length; i++) {
resultado = resultado * numeros[i]
}
return resultado;
}
// let numeros = [1, 4, 7];
// produto(numeros);
function maisMenos(numeros) {
let resultado = [];
let positivo = 0;
let negativo = 0;
let zero = 0;
for (let i = 0; i < numeros.length; i++) {
if(numeros[i] > 0) {
positivo++;
} else if(numeros[i] < 0) {
negativo++;
} else {
zero++;
}
}
resultado[0] = positivo / numeros.length;
resultado[1] = zero / numeros.length;
resultado[2] = negativo / numeros.length;
return resultado;
}
// let numeros = [1, 2, 0, -1];
// maisMenos(numeros);
function escada(altura){
let lista = [];
for(let i = 1; i <= altura; i++){
let espaco = altura - i;
lista.push(" ".repeat(espaco) + "#".repeat(i));
}
return lista;
}
// escada(5);
function acontece(horarios, minimo) {
let total = 0;
for (let i = 0; i < horarios.length; i++) {
if(horarios[i] <= 0) {
total++;
}
}
return (total >= minimo) ? true : false;
}
function aberturas(horarios, minimo) {
let resultado = [];
for (let i = 0; i < horarios.length; i++) {
resultado.push(acontece(horarios[i], minimo));
}
return resultado;
}
// let alunosDaSegunda = [10, -5, 3, 0];
// acontece(alunosDaSegunda, 2);
// acontece(alunosDaSegunda, 3);
// aberturas([[10, -5, 3, 0], [10, -5, 3, 0], [10, 3, 0]], 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment