Reduce, Reduce, Reduce!

const word = 'onomatopoeia'
function letterTally(word){}
function letterTally(word){
const split = word.toLowerCase().split('')
}
function letterTally(word){
const split = word.toLowerCase().split('')
return split.reduce( (acc, curr) => {

}, {})
}
function letterTally(word){
const split = word.toLowerCase().split('');
return split.reduce( (acc, curr) => {
if (acc[curr]) {
acc[curr]++;
return acc;
} else {
acc[curr] = 1;
return acc;
}
}, {})
}
const word = 'onomatopoeia'console.log(letterTally(word))
// prints: { o: 4, n: 1, m: 1, a: 2, t: 1, p: 1, e: 1, i: 1 }

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kamrin Kennedy

Kamrin Kennedy

Full-stack web developer with a background in the service industry, sound design, audio engineering, and theatre performance.