From 2ff2ba659bbda8c182d6233f385fdfce986a9e02 Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 14:46:00 -0300 Subject: [PATCH] refactor: altera solucao maxValue --- 03-maxValue/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..2b87352 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,12 @@ export function maxValue(values) { // implementar logica aqui - -} \ No newline at end of file + var max = values.reduce(function (a, b) { + return Math.max(a, b); + }, -Infinity); + + if (values.length === 0) { + return 0; + } else { + return max; + } +}