You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
406 B
JavaScript
18 lines
406 B
JavaScript
"use strict";
|
|
|
|
// TODO: Document that there's no async version of this because an async version must always map (to a Promise) anyway
|
|
|
|
module.exports = function forEach(iterable, mapper) {
|
|
if (Array.isArray(iterable)) {
|
|
// This may have an optimized implementation
|
|
return iterable.forEach(mapper);
|
|
} else {
|
|
let i = 0;
|
|
|
|
for (let item of iterable) {
|
|
mapper(item, i, iterable);
|
|
i++;
|
|
}
|
|
}
|
|
};
|