Update formatting
This commit is contained in:
@ -7,7 +7,7 @@ lastUpdated: 2020-09-15T16:28:04+03:00
|
||||
|
||||
Creates a pub/sub ([publish–subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with `emit`, `on`, and `off` methods.
|
||||
|
||||
- Use `Object.create(null)` to create an empty `hub` object that does not inherit properties from `Object.prototype`.
|
||||
- Use `Object.create()` with an argument of `null` to create an empty `hub` object that does not inherit properties from `Object.prototype`.
|
||||
- For `emit`, resolve the array of handlers based on the `event` argument and then run each one with `Array.prototype.forEach()` by passing in the data as an argument.
|
||||
- For `on`, create an array for the event if it does not yet exist, then use `Array.prototype.push()` to add the handler
|
||||
- to the array.
|
||||
|
||||
@ -8,7 +8,7 @@ lastUpdated: 2020-10-19T18:51:03+03:00
|
||||
Deep freezes an object.
|
||||
|
||||
- Use `Object.keys()` to get all the properties of the passed object, `Array.prototype.forEach()` to iterate over them.
|
||||
- Call `Object.freeze(obj)` recursively on all properties, applying `deepFreeze()` as necessary.
|
||||
- Call `Object.freeze()` recursively on all properties, applying `deepFreeze()` as necessary.
|
||||
- Finally, use `Object.freeze()` to freeze the given object.
|
||||
|
||||
```js
|
||||
|
||||
@ -8,7 +8,7 @@ lastUpdated: 2020-09-15T16:28:04+03:00
|
||||
Deep maps an object's keys.
|
||||
|
||||
- Creates an object with the same values as the provided object and keys generated by running the provided function for each key.
|
||||
- Use `Object.keys(obj)` to iterate over the object's keys.
|
||||
- Use `Object.keys()` to iterate over the object's keys.
|
||||
- Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
|
||||
|
||||
```js
|
||||
|
||||
@ -9,7 +9,7 @@ Gets the target value in a nested JSON object, based on the given key.
|
||||
|
||||
- Use the `in` operator to check if `target` exists in `obj`.
|
||||
- If found, return the value of `obj[target]`.
|
||||
- Otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.
|
||||
- Otherwise use `Object.values()` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.
|
||||
|
||||
```js
|
||||
const dig = (obj, target) =>
|
||||
|
||||
@ -8,7 +8,7 @@ lastUpdated: 2020-10-22T20:23:47+03:00
|
||||
Finds the first key that satisfies the provided testing function.
|
||||
Otherwise `undefined` is returned.
|
||||
|
||||
- Use `Object.keys(obj)` to get all the properties of the object, `Array.prototype.find()` to test each key-value pair using `fn`.
|
||||
- Use `Object.keys()` to get all the properties of the object, `Array.prototype.find()` to test each key-value pair using `fn`.
|
||||
- The callback receives three arguments - the value, the key and the object.
|
||||
|
||||
```js
|
||||
|
||||
@ -7,7 +7,7 @@ lastUpdated: 2020-11-15T14:43:44+02:00
|
||||
|
||||
Finds all the keys in the provided object that match the given value.
|
||||
|
||||
- Use `Object.keys(obj)` to get all the properties of the object.
|
||||
- Use `Object.keys()` to get all the properties of the object.
|
||||
- Use `Array.prototype.filter()` to test each key-value pair and return all keys that are equal to the given value.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user