Calculates the greatest common divisor between two or more numbers.

Use recursion.
Use array_reduce() with the gcd function to appy to all elements in the $numbers list.
Base case is when y equals 0. In this case, return x.
Otherwise, return the gcd of y and the remainder of the division x/y.

继续阅读 30秒学会 PHP 片段 – gcd

Renders the given DOM tree in the specified DOM element.

Destructure the first argument into type and props, use type to determine if the given element is a text element.
Based on the element’s type, use either Document.createTextNode() or Document.createElement() to create the DOM element.
Use Object.keys(props, adding attributes to the DOM element and setting event listeners, as necessary.
Use recursion to render props.children, if any.
Finally, use Node.appendChild() to append the DOM element to the specified container.

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

Deep maps an object’s keys.

Creates an object with the same values as the provided object and keys generated by running the provided function for each key.
Use Object.keys(obj) to iterate over the object’s keys.
Use Array.prototype.reduce() to create a new object with the same values and mapped keys using fn.

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

Calculates the greatest common divisor of the given numbers.

Define a GCD() function for two numbers, which uses recursion.
Base case is when y equals 0, which returns x.
Otherwise the GCD of y and the remainder of the division x/y is returned.
Define an overload that accepts multiple numbers or an array and use IEnumerable.Aggregate() to apply GCD() to them.

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