function filter(arr, callback) { if (!Array.isArray(arr) || !arr.length || typeof callback !== 'function') { return [] } let rec = [] for (let i = 0; i < arr.length; i++) { if(callback(arr[i], i, arr)) { rec.push(arr[i]) } } return rec } function fn(value, idx, arr) { return value >=5 } let arr = [...Array(10).keys()] console.log(filter(arr, fn))