Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).

Use Array.prototype.every() to check if each passed object has the specified property and if it returns a truthy value.

继续阅读 30秒学会 JavaScript 片段 – truthCheckCollection

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, checking if each one is frozen using Object.isFrozen() and applying deepFreeze() as necessary.
Finally, use Object.freeze() to freeze the given object.

继续阅读 30秒学会 JavaScript 片段 – deepFreeze

Creates an object with keys generated by running the provided function for each key and the same values as the provided object.

Use Object.keys(obj) 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.

继续阅读 30秒学会 JavaScript 片段 – mapKeys

Iterates over all own properties of an object in reverse, running a callback for each one.

Use Object.keys(obj) to get all the properties of the object, Array.prototype.reverse() to reverse their order and Array.prototype.forEach() to run the provided function for each key-value pair. The callback receives three arguments – the value, the key and the object.

继续阅读 30秒学会 JavaScript 片段 – forOwnRight

Maps the values of an array to an object using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value.

Use Array.prototype.reduce() to apply fn to each element in arr and combine the results into an object.
Use el as the key for each property and the result of fn as the value.

继续阅读 30秒学会 JavaScript 片段 – mapObject

Returns a boolean determining if the passed value is an object or not.

Uses the Object constructor to create an object wrapper for the given value.
If the value is null or undefined, create and return an empty object. Οtherwise, return an object of a type that corresponds to the given value.

继续阅读 30秒学会 JavaScript 片段 – isObject

Returns the last 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.reverse() to reverse their order and Array.prototype.find() to test the provided function for each key-value pair.
The callback receives three arguments – the value, the key and the object.

继续阅读 30秒学会 JavaScript 片段 – findLastKey

Creates an object composed of the properties the given function returns truthy for. The function is invoked with two arguments: (value, key).

Use Object.keys(obj) and Array.prototype.filter()to remove the keys for which fn returns a falsy value.
Use Array.prototype.reduce() to convert the filtered keys back to an object with the corresponding key-value pairs.

继续阅读 30秒学会 JavaScript 片段 – pickBy