Removes elements in an array until the passed function returns true. Returns the removed elements.

Loop through the array, using a for...of loop over Array.prototype.entries() until the returned value from the function is true.
Return the removed elements, using Array.prototype.slice().

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

Removes elements from the end of an array until the passed function returns true. Returns the removed elements.

Loop through the array, using a Array.prototype.reduceRight() and accumulating elements while the function returns falsy value.

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

Returns the index of the first element in the provided collection that satisfies the provided testing function, -1 otherwise.

Implement an appropriate function for each type.
Use range to iterate over elements in the given collection, using f to determine if the element matches.
Return the index of the first matching element or -1 if none is found.

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