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)
|
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);
|
||||||
|
|
||||||
}
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user