fix:(longes)finalizando

This commit is contained in:
Andresa Rodrigues Figueira Combat 2022-11-02 15:00:01 -03:00
parent d2f254dd6c
commit cf38216fbf
2 changed files with 21 additions and 33 deletions

View File

@ -1,17 +1,10 @@
export function isAnagram(word1, word2) export function isAnagram(word1, word2) {
for (let index = 0; index < array.length; index++) const retorne = (word) =>
{const element = array[index]; word
{
}
function isAnagram(word1, word2) {
const retorne = word => word
.toLowerCase() .toLowerCase()
.replace(/[^a-z0-9]/gi, '') .replace(/[^a-z0-9]/gi, "")
.split('') .split("")
.sort() .sort()
.join(''); .join("");
return retorne(word1) === retorne(word2); return retorne(word1) === retorne(word2);
} }

View File

@ -1,18 +1,13 @@
export function longestWords(words) { export function longestWords(words) {
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);
});
function findLongestWord(str){ return longestWordsArray;
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
}
} }