source: node_modules/ramda/es/invertObj.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import _curry1 from "./internal/_curry1.js";
2import keys from "./keys.js";
3/**
4 * Returns a new object with the keys of the given object as values, and the
5 * values of the given object, which are coerced to strings, as keys. Note
6 * that the last key found is preferred when handling the same value.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.9.0
11 * @category Object
12 * @sig {s: x} -> {x: s}
13 * @param {Object} obj The object or array to invert
14 * @return {Object} out A new object
15 * @see R.invert
16 * @example
17 *
18 * const raceResults = {
19 * first: 'alice',
20 * second: 'jake'
21 * };
22 * R.invertObj(raceResults);
23 * //=> { 'alice': 'first', 'jake':'second' }
24 *
25 * // Alternatively:
26 * const raceResults = ['alice', 'jake'];
27 * R.invertObj(raceResults);
28 * //=> { 'alice': '0', 'jake':'1' }
29 */
30
31var invertObj =
32/*#__PURE__*/
33_curry1(function invertObj(obj) {
34 var props = keys(obj);
35 var len = props.length;
36 var idx = 0;
37 var out = {};
38
39 while (idx < len) {
40 var key = props[idx];
41 out[obj[key]] = key;
42 idx += 1;
43 }
44
45 return out;
46});
47
48export default invertObj;
Note: See TracBrowser for help on using the repository browser.