isAnagram atualizado

This commit is contained in:
Nathalia Sardou 2022-10-31 17:29:04 -03:00
parent 0f1c198c1e
commit 6e7bf888af
2 changed files with 38 additions and 6 deletions

View File

@ -1,4 +1,13 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
}
if (word1.length !== word2.length) {
return false;
}
var str1 = word1.toLowerCase().toUpperCase().split('').sort().join('');
var str2 = word2.toLowerCase().toUpperCase().split('').sort().join('');
if (str1 === str2) {
return true;
}
return false;
}

View File

@ -1,4 +1,27 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
}
function mostUsedChar(text) {
// implementar logica aqui
text = text.split('').sort();
let cont1 = 0;
let cont2 = 0;
let maior = '';
for (let i = 1; i < text.length; i++) {
if (text[i] != text[i - 1]) {
if (cont2 > cont1) {
cont1 = cont2;
maior = text[i - 1];
}
cont2 = 1;
} else {
cont2++;
}
}
return maior;
}
// Resultados esperados
console.log(mostUsedChar('fdgdfgff'), 'f'); // f
console.log(mostUsedChar('Lorem ipsum'), 'm'); // m
console.log(mostUsedChar('adsassdasd'), 's'); // s
console.log(mostUsedChar('testeeeee'), 'e'); // e