diff --git a/snippets/zipObject.md b/snippets/zipObject.md new file mode 100644 index 000000000..169cdaeb1 --- /dev/null +++ b/snippets/zipObject.md @@ -0,0 +1,11 @@ +### zipObject + +Given an Array of valid property identifiers and an Array of values, `zipObject` returns an object mapping 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 + +```js +const zipObject = (props, values) => props.reduce( ( obj, prop, index ) => (obj[prop] = values[index], obj), {}) +/* +zipObject(['a','b','c'], [1,2]) +*/ +```