Created
July 9, 2022 21:15
-
-
Save batazo/d0c5e801ab02e439581b748a716a42c4 to your computer and use it in GitHub Desktop.
ENUM CREATOR
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
function createEnum(values) { | |
const enumObject = {}; | |
for (const val of values) { | |
enumObject[val] = val; | |
} | |
return Object.freeze(enumObject); | |
} | |
// { Up: 'Up', Down: 'Down', Left: 'Left', Right: 'Right' } | |
const enums = createEnum(['Up', 'Down', 'Left', 'Right']); | |
console.log(enums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment