Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createWordMap(Input) {
- // count the number of appearances for each word
- var wordsMap = {};
- Input.forEach(function(key) {
- if (wordsMap.hasOwnProperty(key)) {
- wordsMap[key]++;
- } else {
- wordsMap[key] = 1;
- }});
- return wordsMap;
- }
- function sortByCount(wordsMap) {
- // create the map that will go into the .cvs file
- var finalWordsArray = [];
- finalWordsArray = Object.keys(wordsMap).map(function(key) {
- return {
- name: key,
- total: wordsMap[key]};
- });
- // sort by count in descending order
- finalWordsArray.sort(function(a, b) {
- return b.total - a.total;
- });
- return finalWordsArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement