Underscore.js Collections: CountBy
HTML
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<a target="parent" href="http://underscorejs.org/#countBy">Learn More</a>
JavaScript
var arr = [1, 2, 3, 4, 5];
var testCountBy = _.countBy(arr, function(num) {
return num % 2 == 0 ? 'even' : 'odd';
});
console.log(testCountBy.odd,testCountBy.even);
//3 2
// 3 is the number of Odd Numbers, 2 is the number of Even Numbers