Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getWordsByFrequency (text) {
- return text
- .replace('\'', '')
- .replace(/\W+/g, ' ')
- .toLowerCase()
- .split(' ')
- .reduce((acc, word) => {
- if (acc[word] === undefined) {
- acc[word] = 1
- } else {
- acc[word] += 1
- }
- return acc
- }, {})
- }
- function getMaxFromObject (obj) {
- return Object.keys(obj)
- .sort((a, b) => obj[a] > obj[b] ? 1 : -1 )
- .map((word) => ({
- word, count: obj[word]
- }))
- }
- getMaxFromObject( getWordsByFrequency(foo) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement