From a817a9a1b1e2cc1d2baa7c04e0d69291acbb9ada Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 15:02:05 -0300 Subject: [PATCH] feat(sumEven): Adicionando algoritmo que retorna a soma de todos os numeros pares de um vetor. --- 06-sum/readme.md | 8 ++++---- 07-sumEven/index.js | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/06-sum/readme.md b/06-sum/readme.md index 1a05476..82a18b0 100644 --- a/06-sum/readme.md +++ b/06-sum/readme.md @@ -5,7 +5,7 @@ Faça um algoritmo que retorne a soma de todos os números de um array ## Exemplo ```js -sum([1, 2, 3, 4, 5]) // 15 -sum([10, 10, 10, 10]) // 40 -sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) // 55 -``` \ No newline at end of file +sum([1, 2, 3, 4, 5]); // 15 +sum([10, 10, 10, 10]); // 40 +sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // 55 +``` diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..fcfc6e3 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,9 @@ export function sumEven(value) { - // implementar logica aqui - -} \ No newline at end of file + let somaPares = 0; + for (let index = 0; index < value.length; index++) { + if (value[index] % 2 === 0) { + somaPares = somaPares + value[index]; + } + } + return somaPares; +} -- 2.34.1