diff --git a/snippets/createEventHub.md b/snippets/createEventHub.md index 043358c44..c8a031882 100644 --- a/snippets/createEventHub.md +++ b/snippets/createEventHub.md @@ -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. diff --git a/snippets/deepFreeze.md b/snippets/deepFreeze.md index 6f136db79..916b2ad64 100644 --- a/snippets/deepFreeze.md +++ b/snippets/deepFreeze.md @@ -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 diff --git a/snippets/deepMapKeys.md b/snippets/deepMapKeys.md index 68c9b386b..1be991065 100644 --- a/snippets/deepMapKeys.md +++ b/snippets/deepMapKeys.md @@ -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 diff --git a/snippets/dig.md b/snippets/dig.md index a91cc9409..95b1bb163 100644 --- a/snippets/dig.md +++ b/snippets/dig.md @@ -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) => diff --git a/snippets/findKey.md b/snippets/findKey.md index 391029dd5..6e14a1de3 100644 --- a/snippets/findKey.md +++ b/snippets/findKey.md @@ -8,11 +8,11 @@ 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 -const findKey = (obj, fn) => +const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj)); ``` diff --git a/snippets/findKeys.md b/snippets/findKeys.md index 31289fc25..942dad8b6 100644 --- a/snippets/findKeys.md +++ b/snippets/findKeys.md @@ -7,12 +7,12 @@ 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. ```js -const findKeys = (obj, val) => +const findKeys = (obj, val) => Object.keys(obj).filter(key => obj[key] === val); ```