From 696061d9ba9d700a64a18a1413b9775fcfc909ea Mon Sep 17 00:00:00 2001 From: Tiago Trevisani Date: Wed, 2 Nov 2022 15:40:30 -0400 Subject: [PATCH] feat(sum):criado algoritimo de soma --- 03-maxValue/index.js | 19 ++++++++++++++++--- 05-isPrime/index.js | 2 +- 06-sum/index.js | 13 +++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..0a6707d 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,17 @@ export function maxValue(values) { - // implementar logica aqui - -} \ No newline at end of file + + const values = [4, 6, 12, 5]; + const values = [9, 234, 312, 999, 21, 2311]; + const values = [533, 234, 23423, 32, 432]; + const values = [5, 4, 3, 2, 1]; + const values = [-1, -5, -10, -45]; + const values = []; + + const maxValue = values.reduce(function(prev, current) { + return prev > current ? prev : current; + }); + return Math.max(values); + +} + + diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..e533dae 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,4 @@ export function isPrime(value) { - // implementar logica aqui + } \ No newline at end of file diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..550706e 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,13 @@ export function sum(values) { - // implementar logica aqui - + var arr = [1]; + var arr = [1, 2]; + var arr = [1, 2, 3]; + var arr = [1, 2, 3, 4,]; + var arr = [1, 2, 3, 4, 5,] + var sum = 0; + + for(var i = 0; i < values.length; i++) { + sum += values[i]; + } + return sum } \ No newline at end of file