From cf38216fbfd526163272a2f0e7f762dfd7412b23 Mon Sep 17 00:00:00 2001 From: Andresa Date: Wed, 2 Nov 2022 15:00:01 -0300 Subject: [PATCH] fix:(longes)finalizando --- 08-isAnagram/index.js | 25 +++++++++---------------- 10-longestWords/index.js | 29 ++++++++++++----------------- 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 35f55de..2415e3c 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,17 +1,10 @@ -export function isAnagram(word1, word2) -for (let index = 0; index < array.length; index++) - {const element = array[index]; - { +export function isAnagram(word1, word2) { + const retorne = (word) => + word + .toLowerCase() + .replace(/[^a-z0-9]/gi, "") + .split("") + .sort() + .join(""); + return retorne(word1) === retorne(word2); } - - function isAnagram(word1, word2) { - const retorne = word => word - - .toLowerCase() - .replace(/[^a-z0-9]/gi, '') - .split('') - .sort() - .join(''); - return retorne(word1) === retorne(word2); - - } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index 98abed0..af9c0ad 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,18 +1,13 @@ export function longestWords(words) { - - - function findLongestWord(str){ - return str.split(" ").sort(function(a, b){return b.length - a.length})[0]; - - var words = str.split(" "); - var longest = " "; - - for (var word of words) { - if (word.length > longest.length) longest = word; - } - return longest.length - } - - - -} \ No newline at end of file + const longestWordsArray = []; + let tamanhoWord = 0; + + words.forEach((word) => { + if (word.length > tamanhoWord) tamanhoWord = word.length; + }); + words.forEach((word) => { + if (word.length == tamanhoWord) longestWordsArray.push(word); + }); + + return longestWordsArray; +}