Returns 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 the provided function for each key-value pair. The callback receives three arguments – the value, the key and the object.

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

Returns 1 if the array is sorted in ascending order, -1 if it is sorted in descending order or 0 if it is not sorted.

Calculate the ordering direction for the first two elements.
Use Object.entries() to loop over array objects and compare them in pairs.
Return 0 if the direction changes or the direction if the last element is reached.

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

Creates an array of arrays, ungrouping the elements in an array produced by zip.

Use Math.max.apply() to get the longest subarray in the array, to make each element an array.
Use Array.prototype.reduce() and Array.prototype.forEach() to map grouped values to individual arrays.

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

Runs a function in a separate thread by using a Web Worker, allowing long running functions to not block the UI.

Create a new Worker using a Blob object URL, the contents of which should be the stringified version of the supplied function.
Immediately post the return value of calling the function back.
Return a promise, listening for onmessage and onerror events and resolving the data posted back from the worker, or throwing an error.

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