Hi there,
Is this a valid way to achieve the result of counting overused words? I felt like the if/else statements only help if you’re trying to access the individual overuse of the word. I came up with this solution that gives me the same result.
const countWords = (accumulator, curValue) => {
return accumulator + curValue;
}
const lessWords = betterWords.map(word => {
let i = 0;
if (overusedWords.includes(word)) {
i++;
}
return i;
})
console.log(lessWords.reduce(countWords))
I watched the video guide to double-check my work and they went with a longer code block of if/else statements. I’m just not sure if the route I took is fine or not. I’d prefer not to learn bad practice.
I took it a step further… so I can pass whatever array I want and have it perform the same action–sorry for the mess, kind of experimenting.
const countWords = (accumulator, curValue) => {
return accumulator + curValue;
}
const countMoreWords = string => {
const myCount = string.map(word => {
let i = 0;
if (overusedWords.includes(word)) {
i++;
}
return i;
})
return myCount;
}
console.log(countMoreWords(betterWords).reduce(countWords))