Returns the angle (theta) between two vectors.

Use Array.prototype.reduce(), Math.pow() and Math.sqrt() to calculate the magnitude of each vector and the scalar product of the two vectors.
Use Math.acos() to calculate the arccos and get the theta value.

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

Calculates the Hamming distance between two values.

Use the XOR operator (^) to find the bit difference between the two numbersand convert to a binary string using fmt.Sprintf() with "%b.
Count and return the number of 1s in the string, using strings.Count().

继续阅读 30秒学会 Golang 片段 – HammingDistance

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

Use Array.from(Math.ceil((end+1-start)/step)) to create an array of the desired length(the amounts of elements is equal to (end-start)/step or (end+1-start)/step for inclusive end), Array.prototype.map() to fill with the desired values in a 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 片段 – initializeArrayWithRangeRight

Initializes an array containing the numbers in the specified range where start and end are inclusive and the ratio between two terms is step.
Returns an error if step equals 1.

Use Array.from(), Math.log() and Math.floor() to create an array of the desired length, Array.prototype.map() to fill with the desired values in a range.
Omit the second argument, start, to use a default value of 1.
Omit the third argument, step, to use a default value of 2.

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

Returns the maximum of a collection, after mapping each element to a value using the provided function.

Use IEnumerable.Select() to map each element to the value returned by the provided selector function, fn.
Use IEnumerable.Max() to get the maximum of the resulting values.

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

Returns the n maximum 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 descending order).

Use Array.prototype.sort() combined with the spread operator (...) to create a shallow clone of the array and sort it in descending 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 片段 – maxN