Code Lab

Modo entrevista. Cronômetro de 3 min, sem dicas e sem autocompletar

Sum of positives

FácilArrays3 min

Write a function sumPositive(numbers) that adds up only the positive numbers of an array and returns the sum. If there is nothing to add, return 0.

Exemplos

sumPositive([1, -4, 7, 12])

Retorna 20

1 + 7 + 12, and -4 is skipped.
sumPositive([])

Retorna 0

sumPositive([-1, -2])

Retorna 0

Fonte

Carregando o editor...
  1. EntradasumPositive([ 1, -4, 7, 12 ])
    Esperado20
  2. EntradasumPositive([])
    Esperado0
  3. EntradasumPositive([ -1, -2 ])
    Esperado0

Os testes ocultos rodam no envio