Skip to content

Instantly share code, notes, and snippets.

@PulsarBlow
Created April 3, 2019 21:14
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 PulsarBlow/fd279f0f5e6085a59c602feb18c5c76b to your computer and use it in GitHub Desktop.
Save PulsarBlow/fd279f0f5e6085a59c602feb18c5c76b to your computer and use it in GitHub Desktop.
Transforms a list of value into a mirrored key:value object
// Transforms a list a value into a mirrored key:value object
// A one-liner functional rewrote of keyMirror NPM package
// https://github.com/STRML/keyMirror/blob/master/index.js
// example :
//
// import keyMirror from './keyMirror.js'
// console.log(keyMirror(['apple', 'orange', 'banana']));
// output: { apple:'apple', orange:'orange', banana:'banana' }
const keyMirror = arr =>
arr.reduce((prev, curr) => ({ ...prev, [curr]: curr }), {});
export default keyMirror;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment