By map method of js
var filter = function(arr, fn) { let filterArr=[]; arr.map((n,i)=>{ if(fn(n,i)){ filterArr.push(n); } }); return filterArr; };