feat: algoritmo 9 e 10

This commit is contained in:
Patrick Reis Santos 2022-11-02 12:58:37 -03:00
parent f981cf4b49
commit aa43fe4a02
2 changed files with 35 additions and 6 deletions

View File

@ -1,4 +1,20 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
}
let freqCounter = [];
let textStr = text.toLowerCase();
for (let char of textStr) {
freqCounter[char] = freqCounter[char] + 1 || 1;
}
let maxCount = 0;
let maxChar = null;
for (let key in freqCounter) {
if (freqCounter[key] > maxCount) {
maxCount = freqCounter[key];
maxChar = key;
}
}
// implementar logica aqui
return maxChar;
}

View File

@ -1,4 +1,17 @@
export function longestWords(words) {
// implementar logica aqui
}
let longestWord = "";
let longestWordsArray = [];
for (let i = 0; i < words.length; i++) {
if (words[i].length >= longestWord.length) {
longestWord = words[i];
}
}
for (let i = 0; i < words.length; i++) {
if (words[i].length == longestWord.length) {
longestWordsArray.push(words[i]);
}
}
return longestWordsArray;
// implementar logica aqui
}