DEV Community

vIctorAlexandre2005
vIctorAlexandre2005

Posted on

Exercitando no hackerRank: Simple Array Sum.

Hoje veremos como resolver um probleminha simples, nada complexo. Precisamos fazer algumas somas para dar, no total, o número inteiro 31 no resultado final. Faremos isso da forma mais simplificada possível. Vem comigo!

Primeiramente criamos uma function simpleArraySum() { }.

Feito isso, dentro dela, atribuimos as somas de número inteiro que chegam até o resultado 31, assim:

 let integger =  29;
  let number = 2;
  let total = 29 + 2;
Enter fullscreen mode Exit fullscreen mode

Feito isso, como podemos fazer o terminal somar e dar 31? Simples, damos um return total, que é a soma de 29 + 2. Assim:

return total
Enter fullscreen mode Exit fullscreen mode

O código fica assim:

function simpleArraySum() {
  let integger =  29;
  let number = 2;
  let total = 29 + 2;

  return total

}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)