39 lines
1.1 KiB
HTML
39 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script>
|
|
/*
|
|
Faça um algoritmo que retorne a a letra mias repetida de uma string
|
|
*/
|
|
function mostUsedChar(text) {
|
|
// implementar logica aqui
|
|
let max = 0,
|
|
maxChar = '';
|
|
text.split('').forEach(function(char){
|
|
if(text.split(char).length > max) {
|
|
max = text.split(char).length;
|
|
maxChar = char;
|
|
}
|
|
});
|
|
return maxChar;
|
|
}
|
|
|
|
// Resultados esperados
|
|
console.log(mostUsedChar("fdgdfgff"), 'f') // f
|
|
console.log(mostUsedChar("Lorem ipsum"), 'm') // m
|
|
console.log(mostUsedChar("adsassdasd"), 's') // s
|
|
console.log(mostUsedChar("testeeeee"), 'e') // e
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html> |