Travis build: 1319

This commit is contained in:
30secondsofcode
2018-01-19 11:53:12 +00:00
parent f8351649c2
commit d6a1a6080b
3 changed files with 28 additions and 3 deletions

View File

@ -271,6 +271,7 @@ average(1, 2, 3);
<details>
<summary>View contents</summary>
* [`defaults`](#defaults)
* [`equals`](#equals-)
* [`forOwn`](#forown)
* [`forOwnRight`](#forownright)
@ -4135,6 +4136,28 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
---
## 🗃️ Object
### defaults
Assigns default values for all properties in an object that are `undefined`.
Use `Object.assign()` to create a new empty object and copy the original one to maintain key order, use `Array.reverse()` and the spread operator `...` to combine the default values from left to right, finally use `obj` again to overwrite properties that originally had a value.
```js
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
```
<details>
<summary>Examples</summary>
```js
defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 }
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### equals ![advanced](/advanced.svg)
Performs a deep comparison between two values to determine if they are equivalent.

File diff suppressed because one or more lines are too long

View File

@ -9,5 +9,5 @@ const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj
```
```js
defaults({ 'a': 1 }, { 'b': 2 }, { 'b': 6 }, { 'a': 3 }); // { a: 1, b: 2 }
defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 }
```