Skip to content

Instantly share code, notes, and snippets.

@bitfishxyz
Created February 17, 2020 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitfishxyz/7d1456ea24ef69b699ae25b4cbb7206f to your computer and use it in GitHub Desktop.
Save bitfishxyz/7d1456ea24ef69b699ae25b4cbb7206f to your computer and use it in GitHub Desktop.
let arr = [1,2,35,33,5,3,3,23,5,6,1,44,33,6];
let resultMap = arr.reduce(function(result, ele){
if (ele in result) {
result[ele]++;
} else {
result[ele] = 1;
}
return result;
}, {});
console.log(resultMap);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment