KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have an array of a couple thousand strings ['7/21/2011', '7/21/2011', '7/21/2011', '7/20/2011', etc] I am currently, running this code to group by the string and get the max group value: var max = 0; var group = {}; arr.map(function (value) { if (group[value]) { group[value]++; } else { group[value] = 1; } max = Math.max(max, group[value]); }); Are there any improvements to make this code run faster? EDIT: The results are in: http://jsperf.com/javascript-array-grouping2 EDIT EDIT: that test was flawed. Mike Samuel 's code was the fastest. 6000 entries test -> http://jsperf.com/javascript-array-grouping2 10K entries test -> http://jsperf.com/javascript-array-grouping
Tags (comma-separated)
Save Edits
Cancel