Skip to content

Instantly share code, notes, and snippets.

@Med116
Created July 22, 2014 21:13
Show Gist options
  • Save Med116/ebaf17bc69d679ab3cf4 to your computer and use it in GitHub Desktop.
Save Med116/ebaf17bc69d679ab3cf4 to your computer and use it in GitHub Desktop.
takes in ar array of strings, and returns a grouped object
module.exports = function(arr,callback){
var groupByObj = {};
if(arr.length == 0){
callback(groupByObj);
}
var count = 0;
arr.forEach(function(val){
count++;
if(groupByObj.hasOwnProperty(val)){
groupByObj[val]++;
}else{
groupByObj[val] = 1;
}
if(arr.length == count){
callback(groupByObj);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment