Skip to content

Commit ae97a2b

Browse files
committed
inverse docs
1 parent 84f241c commit ae97a2b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Functional methods like forEach, map, filter, and other Array methods for Object
1313

1414
[every](https://github.com/tjmehta/object-loops#every)
1515

16+
[inverse](https://github.com/tjmehta/object-loops#inverse)
17+
1618
[filter](https://github.com/tjmehta/object-loops#filter)
1719

1820
[findKey](https://github.com/tjmehta/object-loops#findKey)
@@ -98,6 +100,31 @@ allGreaterThan25 // false
98100
*/
99101
```
100102

103+
## inverse
104+
105+
Creates a new object with keys and values flipped.
106+
107+
* @param {object} [obj] - object to inverse keys and values, not accepted if being used directly on Object.prototype
108+
* @returns {object} newly created object with inversed values
109+
110+
```js
111+
var inverse = require('object-loops/inverse')
112+
113+
var obj = {
114+
foo: 10,
115+
bar: 20,
116+
baz: 30
117+
}
118+
var inversedObj = inverse(obj)
119+
inversedObj /* keys and vals are flipped
120+
{
121+
'10': 'foo',
122+
'20': 'bar',
123+
'30': 'baz'
124+
}
125+
*/
126+
```
127+
101128
## filter
102129

103130
Creates a new object with all entries that pass the test implemented by the provided function.

inverse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ var isInteger = require('101/is-integer')
55
var reduce = require('./reduce')
66

77
/**
8-
* Creates a new object with keys and values swapped.
8+
* Creates a new object with keys and values flipped.
99
* @function module:object-loops/inverse
1010
* @param {object} [obj] - object to inverse keys and values, not accepted if being used directly on Object.prototype
11-
* @returns {object} newly created object with inverseped values
11+
* @returns {object} newly created object with inversed values
1212
*/
1313
module.exports = inverse
1414

0 commit comments

Comments
 (0)