Merge pull request #89 from darrenscerri/to-pairs

Add "Object to key-value pairs"
This commit is contained in:
Angelos Chalaris
2017-12-14 01:44:45 +02:00
committed by GitHub
2 changed files with 14 additions and 0 deletions

View File

@ -44,6 +44,7 @@
* [Measure time taken by function](#measure-time-taken-by-function)
* [Median of array of numbers](#median-of-array-of-numbers)
* [Object from key value pairs](#object-from-key-value-pairs)
* [Object to key value pairs](#object-to-key-value-pairs)
* [Percentile](#percentile)
* [Pick](#pick)
* [Pipe](#pipe)
@ -444,6 +445,13 @@ const objectFromPairs = arr => arr.reduce((a, v) => (a[v[0]] = v[1], a), {});
// objectFromPairs([['a',1],['b',2]]) -> {a: 1, b: 2}
```
### Object to key-value pairs
```js
const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
// objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]])
```
### Percentile
Use `Array.reduce()` to calculate how many numbers are below the value and how many are the same value and

View File

@ -0,0 +1,6 @@
### Object to key-value pairs
```js
const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
// objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]])
```