From 547615682ce046fced1ca6e25258e27da3fe0a91 Mon Sep 17 00:00:00 2001 From: Ayoub Mabrouk Date: Wed, 22 Oct 2025 00:58:29 +0100 Subject: [PATCH] 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. --- lib/internal/util.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index 0b1fa03cf1fab0..63d89051932967 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -326,14 +326,9 @@ function emitExperimentalWarning(feature, messagePrefix, code, ctor) { function filterDuplicateStrings(items, low) { const map = new SafeMap(); - for (let i = 0; i < items.length; i++) { - const item = items[i]; + for (const item of items) { const key = StringPrototypeToLowerCase(item); - if (low) { - map.set(key, key); - } else { - map.set(key, item); - } + map.set(key, low ? key : item); } return ArrayPrototypeSort(ArrayFrom(map.values())); }