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 }

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

React-Native accessibilityRole i18n support for iOS and Android

Create a Full Stack Banking Application using React

THEXII NFT ASIAN ZODIAC

My React Project Experience

Title Case A Sentence Bonfire from freecodecamp.com

Run Android Application On Emulator and Create a build — React Native

Using Prop-Types everywhere

Building cross-platform apps for mobile, web and voice (part I)

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.

More from Medium

CS373 Spring 2022: Nathan Whyte

NPM & YARN, Which package should you choose ?

Is Supple Design the servant of the Deep Model?

S.O.L.I.D Principles.||JavaScript