Aray methods made generic for use with iterators in JavaScript