question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `no-reduce-spread`

See original GitHub issue

Using spread inside a reduce call can turn a O(n) algorithm into O(n**2). See https://www.richsnapp.com/article/2019/06-09-reduce-spread-anti-pattern

Fail

const result = items.reduce((acc, item) => ({
  ...acc,
  [item.name]: item.value,
}, {});

Pass

const result = items.reduce((acc, item) => {
  acc[item.name] = item.value;
  return acc;
}, {})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fregantecommented, Jun 4, 2021

Isn’t this already covered by no-reduce? Both examples are IMHO pretty bad compared to a plain loop:

const result = {};
for (const {name, value} of items) {
  result[name] = value;
}
1reaction
bschlenkcommented, Jun 4, 2021

Would that rule be smart enough to recognize when the item would need to be mapped? This failure example wouldn’t translate directly without mapping the object to an array first

const result = Object.fromEntries(items.map(item => [item.name, item.value]));
Read more comments on GitHub >

github_iconTop Results From Across the Web

SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >
Rule proposal: `no-reduce-spread` #1335 - Issuehunt
Do you want to disallow spread usage in just reduce or are there other array iterator functions (ie. map , filter , etc.)...
Read more >
Reopening of Comment Periods for “Private Fund Advisers
Finally, the proposed rules would amend the Advisers Act compliance rule, which would affect all registered investment advisers, to better ...
Read more >
Federal Register/Vol. 87, No. 46/Wednesday, March 9, 2022 ...
ACTION: Proposed rule. SUMMARY: The Securities and Exchange. Commission is proposing new rules under the Investment Advisers Act of.
Read more >
The Most Curious Rule Proposal in Securities and Exchange ...
I write this post in response to the release (the “Proposing Release”) regarding proposed rules (the “Proposed Rules”) under the Investment ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found