Finds the median of a list of numbers.

Use the params keyword to accept either an array or a variable number of arguments.
Sort the array using Array.sort() and find the median.
Which is either the middle element of the list, if the list length is odd or the average of the two middle elements, if the list length is even.

继续阅读 30秒学会 C# 片段 – Median

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, Array.prototype.map() to make each element an array.
Use Array.prototype.reduce() and Array.prototype.forEach() to map grouped values to individual arrays.

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

Returns a list of elements that exist in both lists.

Use Iterable.toSet() to get the unique values in b.
Use Iterable.toSet(), Iterable.where() and Iterable.contains() to keep only the values in a contained in b, Iterable.toList() to return the appropriate result.

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

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