refactor: replace .forEach() with for-of (#39691)

* refactor: replace `.forEach()` with `for-of`

* refactor docs/fiddles/features/web-hid/renderer.js
This commit is contained in:
Milan Burda 2023-08-31 16:36:43 +02:00 committed by GitHub
parent 7858921a1f
commit 0b0707145b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 144 additions and 132 deletions

View file

@ -57,12 +57,17 @@ function sortTopologically<T> (originalOrder: T[], edgesById: Map<T, T[]>) {
marked.add(mark);
const edges = edgesById.get(mark);
if (edges != null) {
edges.forEach(visit);
for (const edge of edges) {
visit(edge);
}
}
sorted.push(mark);
};
originalOrder.forEach(visit);
for (const edge of originalOrder) {
visit(edge);
}
return sorted;
}
@ -98,24 +103,24 @@ function sortItemsInGroup<T> (group: {before?: T[], after?: T[], id?: T}[]) {
const edges = new Map();
const idToIndex = new Map(group.map((item, i) => [item.id, i]));
group.forEach((item, i) => {
for (const [i, item] of group.entries()) {
if (item.before) {
item.before.forEach(toID => {
for (const toID of item.before) {
const to = idToIndex.get(toID);
if (to != null) {
pushOntoMultiMap(edges, to, i);
}
});
}
}
if (item.after) {
item.after.forEach(toID => {
for (const toID of item.after) {
const to = idToIndex.get(toID);
if (to != null) {
pushOntoMultiMap(edges, i, to);
}
});
}
}
});
}
const sortedNodes = sortTopologically(originalOrder, edges);
return sortedNodes.map(i => group[i]);