feat: colocando um else para a melhoria do codigo

This commit is contained in:
PATRICK DE SOUZA SILVA 2022-11-01 11:31:12 -03:00
parent de7e1ee0d5
commit cb84402691
2 changed files with 26 additions and 14 deletions

View File

@ -6,6 +6,9 @@ export function isAnagram(word1, word2) {
if (word1.toLowerCase().length !== word2.toLowerCase().length) { if (word1.toLowerCase().length !== word2.toLowerCase().length) {
return false return false
} }
else {
for (let i = 0; i < word1.toLowerCase().length; i++) { for (let i = 0; i < word1.toLowerCase().length; i++) {
let res = word1.toLowerCase().charCodeAt(i) - 97 let res = word1.toLowerCase().charCodeAt(i) - 97
array[res] = (array[res] || 0) + 1 array[res] = (array[res] || 0) + 1
@ -20,3 +23,4 @@ export function isAnagram(word1, word2) {
} }
return true return true
} }
}

View File

@ -1,4 +1,12 @@
export function mostUsedChar(text) {
// implementar logica aqui // implementar logica aqui
return "" export function mostUsedChar(text){
const charMap = {};
for (const char of text.toLowerCase()) {
/*5*/ charMap[char] = (charMap[char] || 0) + 1;
} }
return Object.values(charMap).filter((count) => count > 1).length;
}