I have a Javascript array that I would like to split into two based on whether a function called on each element returns true or false. Essentially
true
false
Try this:
function filter(a, fun) { var ret = { good: [], bad: [] }; for (var i = 0; i < a.length; i++) if (fun(a[i]) ret.good.push(a[i]); else ret.bad.push(a[i]); return ret; }