2016-06-01 11:21:26 -07:00
|
|
|
/**
|
2022-10-18 11:19:24 -04:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2016-06-01 11:21:26 -07:00
|
|
|
*
|
2017-09-24 13:48:13 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-01 11:21:26 -07:00
|
|
|
*/
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* turns
|
|
|
|
|
* { 'MUCH ERROR': '0', 'SUCH WRONG': '1' }
|
|
|
|
|
* into
|
|
|
|
|
* { 0: 'MUCH ERROR', 1: 'SUCH WRONG' }
|
|
|
|
|
*/
|
2023-01-31 08:25:05 -05:00
|
|
|
function invertObject(targetObj) {
|
2023-10-31 23:32:31 -04:00
|
|
|
const result = {};
|
2017-11-28 23:13:12 -02:00
|
|
|
const mapKeys = Object.keys(targetObj);
|
2016-06-01 11:21:26 -07:00
|
|
|
|
2018-02-09 16:11:22 +00:00
|
|
|
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
2017-11-28 23:13:12 -02:00
|
|
|
for (const originalKey of mapKeys) {
|
|
|
|
|
const originalVal = targetObj[originalKey];
|
2016-06-01 11:21:26 -07:00
|
|
|
|
|
|
|
|
result[originalVal] = originalKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = invertObject;
|