Skip to content

Instantly share code, notes, and snippets.

@mizoR
Created October 1, 2012 10:08
Show Gist options
  • Save mizoR/3810682 to your computer and use it in GitHub Desktop.
Save mizoR/3810682 to your computer and use it in GitHub Desktop.
var targetUsername = 'ccc';
var jsons = $("#downloaded").val().split("\n");
jsons = $.map(jsons, function (json, i) {
json = JSON.parse(json);
if (json.username === targetUsername) {
return {"key": json.username, "count": 1, "like": json.like}
} else {
return null;
}
});
(function (values) {
var result = {"count": 0, "like": 0};
for (var i in values) {
result.count += values[i].count;
result.like += values[i].like;
}
$('#output').val("targetUsername: " + targetUsername + "\ncount: " + result.count + "\nlike:" + result.like);
})(jsons);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment