Skip to content

Commit 5476156

Browse files
committed
util: refactor filterDuplicateStrings for readability
Modernize filterDuplicateStrings by using for-of loop and ternary operator for cleaner, more idiomatic ES2018 code. Changes: - Replace traditional for loop with for-of iteration - Consolidate conditional map.set() using ternary operator - Eliminate iterator variable reducing cognitive complexity No functional changes, performance remains equivalent.
1 parent 340e619 commit 5476156

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

lib/internal/util.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,9 @@ function emitExperimentalWarning(feature, messagePrefix, code, ctor) {
326326

327327
function filterDuplicateStrings(items, low) {
328328
const map = new SafeMap();
329-
for (let i = 0; i < items.length; i++) {
330-
const item = items[i];
329+
for (const item of items) {
331330
const key = StringPrototypeToLowerCase(item);
332-
if (low) {
333-
map.set(key, key);
334-
} else {
335-
map.set(key, item);
336-
}
331+
map.set(key, low ? key : item);
337332
}
338333
return ArrayPrototypeSort(ArrayFrom(map.values()));
339334
}

0 commit comments

Comments
 (0)