Skip to content

Instantly share code, notes, and snippets.

@SMoni
Last active December 31, 2022 10:04
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 SMoni/80f5bcaa0df92aae20a1cff8b966c7cb to your computer and use it in GitHub Desktop.
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.
'use strict';
const createEnumeration = (...keys) =>
keys.reduce(
(result, key) => Object.assign(result, { [key]: key }),
{}
);
const myEnum = createEnumeration(
'first',
'second',
'third'
);
console.log(myEnum);
@SMoni
Copy link
Author

SMoni commented Dec 31, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment