Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Count of Positives/ Sum of Negatives

We are supposed to return the count of all the positive numbers given an array, and the addition of all the numbers given the same array. Could someone tell me what I am doing wrong please. I would really appreciate it. This is what I put as my code(JavaScript):

function countPositivesSumNegatives(input) {
  let arr = [];

  let count = 0;

  let neg = 0;

  for (let i = 0; i <= input.length; i++) {
    if (input[i] > 0) {
      count++;
    } else if (input[i] < 0) {
      neg += input[i];
    }
    return arr.push(count, neg);
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

function countPositivesSumNegatives(input) {
  let count = 0;
  let neg = 0;

  for (let i = 0; i <= input.length; i++) {
    if (input[i] > 0) {
      count++;
    } else if (input[i] < 0) {
      neg += input[i];
    }
  }
  // Return outside the for loop
  return [count, neg];
}

console.log(countPositivesSumNegatives([1,2,4,-1,0,-2,3,-4]))

about 4 years ago · Juan Pablo Isaza Relatório

0

function countPositivesSumNegatives(input) {
  let count = 0;
  let neg = 0;

  for (const number of input) {
    if (number > 0) {
      count++;
    } else if (number < 0) {
      neg += number;
    }
  }
  
  return [count, neg];
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda