forked from M3-Academy/challenge-algorithms-v2.0
fix:(longes)finalizando
This commit is contained in:
parent
d2f254dd6c
commit
cf38216fbf
@ -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);
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user