Filters out the elements of an array, that have one of the specified values. Use Array.filter() to create an array excluding(using !Array.includes()) all given values. {代码...}
Returns all elements in an array except for the first one. Return Array.slice(1) if the array's length is more than 1, otherwise, return the whole array. {代码...}
Gets n random elements at unique keys from array up to the size of array. Shuffle the array using the Fisher-Yates algorithm. Use Array.slice() to get the first n elements. Omit the second argument, n to get only one element at random from the array. {代码...}
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.sort() combined with the spread operator (...) to create a shallow clone of the array and sort it in descendi...
Flattens an array up to the specified depth. Use recursion, decrementing depth by 1 for each level of depth. Use Array.reduce() and Array.concat() to merge elements or arrays. Base case, for depth equal to 1 stops recursion. Omit the second element, depth to flatten only to a depth of 1 (single f...
有意思 最近很火的github上的库30-seconds-of-code,特别有意思,代码也很优雅。 能学es6 自己翻译,能学英语 代码很美,很优雅,美即正义 函数式表达,享受 arrayGcd Calculates the greatest common denominator (gcd) of an array of numbers. Use Array.reduce() and the gcd formula (uses recursion) to calculate...