Skip to content

Commit 830f2a2

Browse files
committed
Use for loops in preference to forEach
Change-type: patch
1 parent cae9095 commit 830f2a2

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

src/index.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class Poll<T extends PromiseResultTypes> {
269269
// Catch errors in event subscribers so that they don't trigger
270270
// the 'catch' below, and that subsequent subscribers will still
271271
// be called
272-
this.subscribers.data.forEach((fn) => {
272+
for (const fn of this.subscribers.data) {
273273
try {
274274
fn(response);
275275
} catch (error) {
@@ -278,14 +278,14 @@ class Poll<T extends PromiseResultTypes> {
278278
error,
279279
);
280280
}
281-
});
281+
}
282282
} catch (err: any) {
283283
if (this.stopped) {
284284
return;
285285
}
286286
this.restartTimeout();
287287

288-
this.subscribers.error.forEach((fn) => {
288+
for (const fn of this.subscribers.error) {
289289
try {
290290
fn(err);
291291
} catch (error) {
@@ -294,7 +294,7 @@ class Poll<T extends PromiseResultTypes> {
294294
error,
295295
);
296296
}
297-
});
297+
}
298298
}
299299
}
300300

@@ -408,19 +408,18 @@ const bracketJoin = (arr: string[][], separator: string): string[] => {
408408
return arr[0];
409409
}
410410
const resultArr: string[] = [];
411-
arr
412-
.map((subArr) => {
413-
if (subArr.length > 1) {
414-
return `(${subArr.join('')})`;
415-
}
416-
return subArr[0];
417-
})
418-
.forEach((str, i) => {
419-
if (i !== 0) {
420-
resultArr.push(separator);
421-
}
422-
resultArr.push(str);
423-
});
411+
const mappedArr = arr.map((subArr) => {
412+
if (subArr.length > 1) {
413+
return `(${subArr.join('')})`;
414+
}
415+
return subArr[0];
416+
});
417+
for (let i = 0; i < mappedArr.length; i++) {
418+
if (i !== 0) {
419+
resultArr.push(separator);
420+
}
421+
resultArr.push(mappedArr[i]);
422+
}
424423
return resultArr;
425424
};
426425

0 commit comments

Comments
 (0)