/*
--- Examples
maxChar("abcccccccd") === "c"
maxChar("apple 1231111") === "1"
walk through array of characters
if list exists with char as key, add char to list
compare lengths of all lists and return largest list
Write a function that returns the number of vowels
used in a string. Vowels are the characters 'a', 'e'
'i', 'o', and 'u'.
--- Examples
vowels('Hi There!') --> 3
vowels('Why do you ask?') --> 4
vowels('Why?') --> 0
or
Write a function that accepts a string. The function should
capitalize the first letter of each word in the string then
return the capitalized string.
--- Examples
capitalize('a short sentence') --> 'A Short Sentence'
capitalize('a lazy fox') --> 'A Lazy Fox'
capitalize('look, it is working!') --> 'Look, It Is Working!'
*/
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
JavaScript
// find elements
var banner = $("#banner-message")
var button = $("button")
function maxChar(str) {
let uniqueKeys = [];
for (var i=0;i<256;i++){
uniqueKeys[i]=0;
}
for (var i=0;i<str.length;i++) {
currentChar = Math.floor(str.charAt(i));
uniqueKeys[currentChar]++;
}
console.log(uniqueKeys);
}
// handle click and add class
button.on("click", () => {
maxChar("112");
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.