From 293b56673c1e8a591b20d018fcc408fa0695f036 Mon Sep 17 00:00:00 2001 From: Caio Thurler Date: Sun, 30 Oct 2022 19:45:47 -0300 Subject: [PATCH] feat: funcao sumEven --- 07-sumEven/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..c5e092f 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,15 @@ export function sumEven(value) { // implementar logica aqui - -} \ No newline at end of file + let total = 0 + let pares = [] + for (let i = 0; i < value.length; i++) { + if (value[i] % 2 == 0) { + pares.push(value[i]) + } + } + for (let i = 0; i < pares.length; i++) { + total += pares[i]; // adiciona o valor do indice (que aumenta com o loop) no total + } + value = []; + return total; // torna value = total + } \ No newline at end of file