Compares two objects to determine if the first one contains equivalent property values to the second one.

Use Object.keys(source) to get all the keys of the second object, then Array.prototype.every(), Object.hasOwnProperty() and strict comparison to determine if all keys exist in the first object and have the same values.

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

Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.

Check if the array is sorted in descending order (loosely).
Use Array.prototype.map() to apply the iterator function to all elements of the array.
Use Array.prototype.reverse() and Array.prototype.findIndex() to find the appropriate last index where the element should be inserted, based on the provided iterator function.

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

Mutates the original array to filter out the values specified. Returns the removed elements.

Use Array.prototype.filter() and Array.prototype.includes() to pull out the values that are not needed.
Use Array.prototype.length = 0 to mutate the passed in an array by resetting it’s length to zero and Array.prototype.push() to re-populate it with only the pulled values.
Use Array.prototype.push() to keep track of pulled values

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

Given a predicate function and a prop string, this curried function will then take an object to inspect by calling the property and passing it to the predicate.

Summon prop on obj, pass it to a provided predicate function and return a masked boolean.

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

Encode a set of form elements as a query string.

Use the FormData constructor to convert the HTML form to FormData, Array.from() to convert to an array, passing a map function as the second argument.
Use Array.prototype.map() and window.encodeURIComponent() to encode each field’s value.
Use Array.prototype.join() with appropriate argumens to produce an appropriate query string.

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

Returns the index of the function in an array of functions which executed the fastest.

Use Array.prototype.map() to generate an array where each value is the total time taken to execute the function after iterations times. Use the difference in performance.now() values before and after to get the total time in milliseconds to a high degree of accuracy.
Use Math.min() to find the minimum execution time, and return the index of that shortest time which corresponds to the index of the most performant function.
Omit the second argument, iterations, to use a default of 10,000 iterations. The more iterations, the more reliable the result but the longer it will take.

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