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)
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);
}

View File

@ -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
}
}
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;
}