## 30秒学会 JavaScript 片段 – vectorAngle

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秒学会 Dart 片段 – mapNumRange

Maps a number from one range to another range.

Returns `n` mapped between `outMin``outMax` from `inMin``inMax`.

## 30秒学会 Golang 片段 – HammingDistance

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 `1`s in the string, using `strings.Count()`.

## 30秒学会 JavaScript 片段 – initializeArrayWithRangeRight

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 片段 – geometricProgression

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秒学会 PHP 片段 – clampNumber

Clamps `\$num` within the inclusive range specified by the boundary values `\$a` and `\$b`.

If `\$num` falls within the range, return `\$num`.
Otherwise, return the nearest number in the range, using `min()` and `max()`.

## 30秒学会 C# 片段 – MaxBy

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秒学会 Golang 片段 – Sum

Returns the sum of two or more numbers.

Use `range` to iterate over the values of `nums`, adding each value to `sum`.

## 30秒学会 JavaScript 片段 – maxN

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.