Merge pull request 'feature/is-anagram' (#3) from feature/is-anagram into develop
Reviewed-on: #3
This commit is contained in:
commit
a12862271b
@ -1,4 +1,26 @@
|
||||
export function isAnagram(word1, word2) {
|
||||
// implementar logica aqui
|
||||
|
||||
var array = {}
|
||||
|
||||
if (word1.toLowerCase().length !== word2.toLowerCase().length) {
|
||||
return false
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
for (let i = 0; i < word1.toLowerCase().length; i++) {
|
||||
let res = word1.toLowerCase().charCodeAt(i) - 97
|
||||
array[res] = (array[res] || 0) + 1
|
||||
}
|
||||
|
||||
}
|
||||
for (let j = 0; j < word2.toLowerCase().length; j++) {
|
||||
let res = word2.toLowerCase().charCodeAt(j) - 97
|
||||
if (!array[res]) {
|
||||
return false
|
||||
}
|
||||
array[res]--
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,12 @@
|
||||
export function mostUsedChar(text) {
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user