forked from M3-Academy/challenge-algorithms-v2.0
feat(mostUsedChar): adicionando resolucao desafio 9
mostRepeatedChar
This commit is contained in:
parent
78aaef7f2f
commit
940dba1b38
@ -1,4 +1,15 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
const value = text.toLocaleLowerCase().split("").sort();
|
||||
|
||||
let counts = {};
|
||||
value.forEach(function (x) {
|
||||
counts[x] = (counts[x] || 0) + 1;
|
||||
});
|
||||
|
||||
const maior = Object.keys(counts).sort(function (a, b) {
|
||||
return counts[a] > counts[b] ? -1 : counts[b] > counts[a] ? 1 : 0;
|
||||
})[0];
|
||||
|
||||
return maior;
|
||||
}
|
Loading…
Reference in New Issue
Block a user