Skip to content

Conversation

@Fdawgs
Copy link
Member

@Fdawgs Fdawgs commented Jan 8, 2025

Ended up stumbling across this blog post over the holidays, which covers why using spread ({...obj}) syntax in accumulators like reduce is a bad idea.

TL;DR: it causes a time complexity of O(n^2) instead of O(n) because it's creating an increasingly growing new object on every iteration. With object.assign, we're mutating the accumulator rather than creating a new object.

Checklist

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@Fdawgs Fdawgs merged commit 1ea275f into master Jan 8, 2025
13 checks passed
@Fdawgs Fdawgs deleted the perf/util branch January 8, 2025 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants