MCPcopy Index your code
hub / github.com/react/react / invertObject

Function invertObject

scripts/error-codes/invertObject.js:15–27  ·  view source on GitHub ↗

* turns * { 'MUCH ERROR': '0', 'SUCH WRONG': '1' } * into * { 0: 'MUCH ERROR', 1: 'SUCH WRONG' }

(targetObj)

Source from the content-addressed store, hash-verified

13 * { 0: 'MUCH ERROR', 1: 'SUCH WRONG' }
14 */
15function invertObject(targetObj) {
16 const result = {};
17 const mapKeys = Object.keys(targetObj);
18
19 // eslint-disable-next-line no-for-of-loops/no-for-of-loops
20 for (const originalKey of mapKeys) {
21 const originalVal = targetObj[originalKey];
22
23 result[originalVal] = originalKey;
24 }
25
26 return result;
27}
28
29module.exports = invertObject;

Callers 2

Calls 1

keysMethod · 0.80

Tested by

no test coverage detected