Skip to content

Instantly share code, notes, and snippets.

@daejinseok
Last active September 10, 2020 13:56
Show Gist options
  • Save daejinseok/9dbf1fcdc3eb7e1796532c05ee6c39fb to your computer and use it in GitHub Desktop.
Save daejinseok/9dbf1fcdc3eb7e1796532c05ee6c39fb to your computer and use it in GitHub Desktop.
function makeHashCount( arr ){
const m = new Map();
arr.forEach( k => {
m.set(k, (m.get(k)||0) + 1 );
})
return m;
}
console.log( makeHashCount([1,2,3,3]) );
// Map(3) { 1 => 1, 2 => 1, 3 => 2 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment