I need to get the total count of each word in a string .
I wanted to achieve it using reducer since i am a beginner in the reduce method i could not solve it .
getWordOccurence = (str1) => {
splitStr = str1.split(' ');
let count=0;
const wordCount = splitStr.reduce((acc, curr) => ({...acc,[curr]:count}),{})
console.log(wordCount)
};
getWordOccurence('apple orange apple banana grapes ?');
Expected : {"apple":2,"orange":1,"banana":1,"grape":1}