Skip to content

Comments

util: refactor filterDuplicateStrings for readability#60347

Open
Ayoub-Mabrouk wants to merge 1 commit intonodejs:mainfrom
Ayoub-Mabrouk:modernize-filter-duplicate-strings
Open

util: refactor filterDuplicateStrings for readability#60347
Ayoub-Mabrouk wants to merge 1 commit intonodejs:mainfrom
Ayoub-Mabrouk:modernize-filter-duplicate-strings

Conversation

@Ayoub-Mabrouk
Copy link

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.

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.
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Oct 22, 2025
@ex1st
Copy link

ex1st commented Oct 23, 2025

Hi @Ayoub-Mabrouk as I know, the Node.js team is trying to avoid the for-of iteration. Please check https://github.com/nodejs/node/blob/main/doc/contributing/primordials.md#unsafe-array-iteration

@Ayoub-Mabrouk
Copy link
Author

Hi @Ayoub-Mabrouk as I know, the Node.js team is trying to avoid the for-of iteration. Please check https://github.com/nodejs/node/blob/main/doc/contributing/primordials.md#unsafe-array-iteration

Thanks alot 🙏👌

@ljharb
Copy link
Member

ljharb commented Oct 23, 2025

for-of is much slower than a for loop.

@Ayoub-Mabrouk
Copy link
Author

for-of is much slower than a for loop.

Thanks for the feedback

@aduh95 aduh95 added the stalled Issues and PRs that are stalled. label Feb 17, 2026
@github-actions
Copy link
Contributor

This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. stalled Issues and PRs that are stalled. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants