From ac37e689f82ea274843ad59dc2d05bc7a85504ef Mon Sep 17 00:00:00 2001 From: Matheus Brollo Dauter Date: Wed, 2 Nov 2022 12:48:51 -0300 Subject: [PATCH] feat(10): finished --- 09-mostRepeatedChar/index.js | 2 +- 10-longestWords/index.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index d288f02..ad0fa71 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -5,7 +5,7 @@ export function mostUsedChar(text) { let mostUsed = ''; text.split('').forEach((letter) => { if (text.split(letter).length > maxLetter) { - maxLetter = text.split(letter).length - 1; + maxLetter = text.split(letter).length; mostUsed = letter; } }) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..fb9d583 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,13 @@ export function longestWords(words) { // implementar logica aqui - -} \ No newline at end of file + + return words.reduce((longest, sentence, i) => { + if (!i || longest[0].length < sentence.length) { + return [sentence]; + } + if (longest[0].length === sentence.length) { + longest.push(sentence); + } + return longest; + }, []); + } \ No newline at end of file