Skip to content

Instantly share code, notes, and snippets.

@jed
Created October 27, 2010 08:41
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 jed/648676 to your computer and use it in GitHub Desktop.
Save jed/648676 to your computer and use it in GitHub Desktop.
each, extend, and map in one function
function invert( index, fn ) {
var key = index.length, val
if ( key > 0 ) while ( key-- ) this[ val = index[ key ] ] = fn ? fn( val, key ) : key
else for ( key in index ) this[ val = index[ key ] ] = fn ? fn( val, key ) : key
return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment