Created
April 3, 2019 21:14
-
-
Save PulsarBlow/fd279f0f5e6085a59c602feb18c5c76b to your computer and use it in GitHub Desktop.
Transforms a list of value into a mirrored key:value object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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