function drop(arr, func) { // Drop them elements. //return arr; var tmp; var res = []; for(var i=0,len=arr.length;i<len;i++){ tmp = arr.shift(); if(func(tmp)){ //需要置回弹出的元素 arr.unshift(tmp); break; } } return arr; } drop([1, 2, 3], function(n) {return n < 3; });
或
function drop(arr, func) { // Drop them elements. //return arr; while(!func(arr[0]) && arr.length > 0){ arr.shift(); } return arr; } drop([1, 2, 3], function(n) {return n < 3; });