移除数组中的元素, 直到传递的函数返回true。返回数组中的其余元素。
在数组中循环, 使用Array.shift()将数组的第一个元素除去, 直到函数的返回值为true。返回其余元素。
const dropElements = (arr, func) => {
while (arr.length > 0 && !func(arr[0])) arr.shift();
return arr;
};
// dropElements([1, 2, 3, 4], n => n >= 3) -> [3,4] Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8