Merge pull request #282 from skatcat31/zipObject

[FEATURE] Add zipObject
This commit is contained in:
Angelos Chalaris
2017-12-21 11:14:00 +02:00
committed by GitHub
2 changed files with 12 additions and 0 deletions

11
snippets/zipObject.md Normal file
View File

@ -0,0 +1,11 @@
### zipObject
Given an array of valid property identifiers and an array of values, return an object associating the properties to the values.
Since an object can have undefined values but not undefined property pointers, the array of properties is used to decide the structure of the resulting object using `Array.reduce()`.
```js
const zipObject = ( props, values ) => props.reduce( ( obj, prop, index ) => ( obj[prop] = values[index], obj ), {} )
// zipObject(['a','b','c'], [1,2]) -> {a: 1, b: 2, c: undefined}
// zipObject(['a','b'], [1,2,3]) -> {a: 1, b: 2}
```

View File

@ -118,3 +118,4 @@ validateEmail:utility
validateNumber:utility validateNumber:utility
without:array without:array
zip:array zip:array
zipObject:array