forked from M3-Academy/challenge-algorithms-v2.0
Merge pull request 'feat: solucao mostRepeatedChar' (#9) from feature/solucao-mostRepeatedChar into development
Reviewed-on: #9
This commit is contained in:
commit
64408391b9
@ -1,4 +1,17 @@
|
|||||||
export function mostUsedChar(text) {
|
export function mostUsedChar(text) {
|
||||||
// implementar logica aqui
|
// implementar logica aqui
|
||||||
return ""
|
let arr = text.toLowerCase().split("").sort();
|
||||||
}
|
let mostRepeated = null;
|
||||||
|
let moreOccurrences = -1;
|
||||||
|
|
||||||
|
let count = 1;
|
||||||
|
for (let i = 1; i <= arr.length; i++) {
|
||||||
|
if (i < arr.length && arr[i] === arr[i - count]) {
|
||||||
|
count++;
|
||||||
|
} else if (count > moreOccurrences) {
|
||||||
|
mostRepeated = arr[i - 1];
|
||||||
|
moreOccurrences = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return `${mostRepeated}`;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user