Skip to content

Instantly share code, notes, and snippets.

@canterberry
Created February 22, 2016 16:33
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 canterberry/342f70bb815b57a0c9dd to your computer and use it in GitHub Desktop.
Save canterberry/342f70bb815b57a0c9dd to your computer and use it in GitHub Desktop.
Code Golf: Hash Inversion: JavaScript Solution (165 characters)
var i,x,y,f,k=[],v=[];for(i in h){k.push(i);v.push(h[i]);}h={};for(i in v){x=v[i];y=k[i];f=(a,b)=>{b=h[a];h[a]=(b?b.map?b.concat([y]):[b,y]:y)};x.map?x.map(f):f(x);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment