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