Skip to content

Commit

Permalink
inverse docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Mar 18, 2016
1 parent 84f241c commit ae97a2b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Functional methods like forEach, map, filter, and other Array methods for Object

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

[inverse](https://github.com/tjmehta/object-loops#inverse)

[filter](https://github.com/tjmehta/object-loops#filter)

[findKey](https://github.com/tjmehta/object-loops#findKey)
Expand Down Expand Up @@ -98,6 +100,31 @@ allGreaterThan25 // false
*/
```

## inverse

Creates a new object with keys and values flipped.

* @param {object} [obj] - object to inverse keys and values, not accepted if being used directly on Object.prototype
* @returns {object} newly created object with inversed values

```js
var inverse = require('object-loops/inverse')

var obj = {
foo: 10,
bar: 20,
baz: 30
}
var inversedObj = inverse(obj)
inversedObj /* keys and vals are flipped
{
'10': 'foo',
'20': 'bar',
'30': 'baz'
}
*/
```

## filter

Creates a new object with all entries that pass the test implemented by the provided function.
Expand Down
4 changes: 2 additions & 2 deletions inverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var isInteger = require('101/is-integer')
var reduce = require('./reduce')

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

Expand Down

0 comments on commit ae97a2b

Please sign in to comment.