Last active
December 31, 2022 10:04
-
-
Save SMoni/80f5bcaa0df92aae20a1cff8b966c7cb to your computer and use it in GitHub Desktop.
Simple function to create an enumeration (sort of), in which the key and the value match.
This file contains 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
'use strict'; | |
const createEnumeration = (...keys) => | |
keys.reduce( | |
(result, key) => Object.assign(result, { [key]: key }), | |
{} | |
); | |
const myEnum = createEnumeration( | |
'first', | |
'second', | |
'third' | |
); | |
console.log(myEnum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackblitz.com/edit/js-kngxa2