2016-06-02 02:21:26 +08:00
|
|
|
/**
|
2022-10-18 23:19:24 +08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2016-06-02 02:21:26 +08:00
|
|
|
*
|
2017-09-25 04:48:13 +08: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-02 02:21:26 +08:00
|
|
|
*/
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* turns
|
|
|
|
|
* { 'MUCH ERROR': '0', 'SUCH WRONG': '1' }
|
|
|
|
|
* into
|
|
|
|
|
* { 0: 'MUCH ERROR', 1: 'SUCH WRONG' }
|
|
|
|
|
*/
|
2023-01-31 21:25:05 +08:00
|
|
|
function invertObject(targetObj) {
|
2023-01-10 06:00:36 +08:00
|
|
|
const result /*: {[string]: string} */ = {};
|
2017-11-29 09:13:12 +08:00
|
|
|
const mapKeys = Object.keys(targetObj);
|
2016-06-02 02:21:26 +08:00
|
|
|
|
2018-02-10 00:11:22 +08:00
|
|
|
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
2017-11-29 09:13:12 +08:00
|
|
|
for (const originalKey of mapKeys) {
|
|
|
|
|
const originalVal = targetObj[originalKey];
|
2016-06-02 02:21:26 +08:00
|
|
|
|
|
|
|
|
result[originalVal] = originalKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = invertObject;
|