Skip to content

Instantly share code, notes, and snippets.

@richie3366
Created February 4, 2019 17:28
Show Gist options
  • Save richie3366/41c8f785d19a0513b3aa3774b61981ab to your computer and use it in GitHub Desktop.
Save richie3366/41c8f785d19a0513b3aa3774b61981ab to your computer and use it in GitHub Desktop.
let langStats = {}
data.forEach(e => {
langStats[e.tweet_lang] = (langStats[e.tweet_lang] || 0) + 1
})
console.log(Object.entries(langStats).sort(([langA, countA], [langB, countB]) => countA < countB ? 1 : -1)
.slice(0, 10).map(([lang, count]) => `${lang} ${Math.floor((count / data.length) * 100)}%`))
/*
Outputs:
[ 'en 29%',
'th 27%',
'ja 24%',
'ar 6%',
'ko 2%',
'es 2%',
'in 1%',
'und 1%',
'tr 1%',
'fr 0%' ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment