Created
September 29, 2022 20:27
-
-
Save NuroDev/62956708852a6679779114904d201eaf to your computer and use it in GitHub Desktop.
π Flip Entries β Take the elements of an object & swap the keys with values
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 flipEntries <TValue = unknown> (obj: Record<string, TValue>) { | |
return Object.fromEntries(Object.entries(obj).map(([key, value]) => Array.isArray(value) ? [...value.map((v) => [v, key])] : [[value, key]]).flat()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment