Couldn't you use Array.filter for this?