Last active
April 15, 2016 21:29
-
-
Save g5codyswartz/3a39448d5919588fb5627ca0344fd4da to your computer and use it in GitHub Desktop.
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
// https://gist.github.com/g5codyswartz/3a39448d5919588fb5627ca0344fd4da | |
var authors = {}; | |
var author; | |
$(".author_cell").each(function(i,e) { | |
author = $(e).text().trim(); | |
if (!authors.hasOwnProperty(author)) authors[author] = 0; | |
authors[author]++ | |
}); | |
// http://jsfiddle.net/lalatino/mcuzr/ | |
function sortObject(obj) { | |
var arr = []; | |
var prop; | |
for (prop in obj) { | |
if (obj.hasOwnProperty(prop)) { | |
arr.push({ | |
'key': prop, | |
'value': obj[prop] | |
}); | |
} | |
} | |
arr.sort(function(a, b) { | |
return b.value - a.value; | |
}); | |
return arr; // returns array | |
} | |
authors = sortObject(authors); | |
function keyValueizer(obj) { | |
var newObj = {}; | |
obj.forEach(function(k,v) { | |
newObj[k['key']] = k['value']; | |
}); | |
return newObj; | |
} | |
authors = keyValueizer(authors); | |
console.log(JSON.stringify(authors)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment