Returns the n minimum elements from the provided array.
If n is greater than or equal to the provided array’s length, then return the original array (sorted in ascending order).

Use Array.prototype.sort() combined with the spread operator (...) to create a shallow clone of the array and sort it in ascending order.
Use Array.prototype.slice() to get the specified number of elements.
Omit the second argument, n, to get a one-element array.

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

Returns a list of elements that exist in both lists, after applying the provided function to each element of both.

Use Iterable.toSet() and Iterable.map() to get the unique values in b after applying fn to them.
Use Iterable.map() to apply fn to all the values of a, Iterable.toSet(), Iterable.where() and Iterable.contains() to keep only the values in the resulting list contained in the unique mapped values of b, Iterable.toList() to return the appropriate result.

继续阅读 30秒学会 Dart 片段 – intersectionBy

Initializes an array containing the numbers in the specified range where start and end are inclusive with their common difference step.

Use Array.from() to create an array of the desired length, (end - start + 1)/step, and a map function to fill it with the desired values in the given range.
You can omit start to use a default value of 0.
You can omit step to use a default value of 1.

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