Skip to content

Instantly share code, notes, and snippets.

@ravinsinghd
Last active August 16, 2017 21:09
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 ravinsinghd/8a5c8f8c476baf52af1ca73e2f96bf61 to your computer and use it in GitHub Desktop.
Save ravinsinghd/8a5c8f8c476baf52af1ca73e2f96bf61 to your computer and use it in GitHub Desktop.
// Approach 1
function getMapping(){
const tagMap = {};
this.selectedTags.forEach(( tag, index ) => {
if ( tag !== undefined ) {
tagMap[ tag ] = this.headers[ index ];
}
} )
return tagMap;
}
// Approach 2
function getMapping(){
return this.selectedTags
.filter( tag => tag !== undefined )
.reduce(( map, tag, index ) => map[ tag ] = this.headers[ index ], {} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment