Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!
We spend hours on Instagram and YouTube and waste money on coffee and fast food, but wonβt spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!
Learn from Guru Rajesh Kumar and double your salary in just one year.
Requirement
Which word occurs the most frequently in the check one field, such as answer one, answer two, or answer three, per the specified criteria

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wordCounts = { | |
answerone: 0, | |
answertwo: 0, | |
answerthree: 0, | |
answerfour: 0 | |
}; | |
data[0].checkone.forEach(item => { | |
if (item === 'answerone') { | |
wordCounts.answerone++; | |
} else if (item === 'answertwo') { | |
wordCounts.answertwo++; | |
} else if (item === 'answerthree') { | |
wordCounts.answerthree++; | |
} else if (item === 'answerfour') { | |
wordCounts.answerfour++; | |
} | |
}); | |
let highestWord = ''; | |
let highestCount = 0; | |
for (const word in wordCounts) { | |
if (wordCounts[word] > highestCount) { | |
highestWord = word; | |
highestCount = wordCounts[word]; | |
} | |
} | |
console.log('Highest word:', highestWord); | |
console.log('Highest count:', highestCount); |