SOURCE

function remove(array, iterate) {
    let len = array.length >>> 0;
    let idx = 0;
    let result = [];
    while(len-- > 0){
        if(iterate(array[len])){
            result[idx++] = array[len];
            array.splice(len,1)
        }
    }
    return result;
}
var array = [1, 2, 3, 4];

var evens = remove(array, function(n) {
  return n % 2 == 0;
});
 
console.log(array);
 
console.log(evens);
console 命令行工具 X clear

                    
>
console