Skip to content

fix(reduce, reduceRight): respect nullish accumulators - #1742

Merged
raon0211 merged 2 commits into
mainfrom
codex/fix-compat-reduce-nullish-accumulator
May 29, 2026
Merged

raon0211 merged 2 commits into
mainfrom
codex/fix-compat-reduce-nullish-accumulator

Conversation

@raon0211

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1741.

es-toolkit/compat now matches lodash when reduce or reduceRight receives an explicit null or undefined accumulator.

Changes

  • Detect whether an accumulator was provided using argument count, matching lodash's arguments.length < 3 behavior.
  • Add compat tests for explicit null and undefined accumulators across arrays and objects.
  • Fix existing docs curly lint errors so the full lint command completes.

Test results

  • mise exec node@24.13.0 -- yarn typecheck
  • mise exec node@24.13.0 -- yarn lint
  • mise exec node@24.13.0 -- yarn vitest run src/compat/array/reduce.spec.ts src/compat/array/reduceRight.spec.ts
  • mise exec node@24.13.0 -- yarn vitest run

raon0211 added 2 commits May 29, 2026 20:52
Match lodash by treating accumulator presence as an argument-count check, so explicit null and undefined initial values are passed to iteratees.

Add compat coverage for reduce and reduceRight over arrays and objects.
Add braces to existing single-line early returns so the repository lint command can complete without errors.
@vercel

vercel Bot commented May 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment May 29, 2026 11:57am

Request Review

@raon0211
raon0211 marked this pull request as ready for review May 29, 2026 12:03
@raon0211
raon0211 requested a review from dayongkr as a code owner May 29, 2026 12:03
@raon0211 raon0211 changed the title fix[reduce, reduceRight]: respect nullish accumulators fix(reduce, reduceRight): respect nullish accumulators May 29, 2026
@raon0211
raon0211 merged commit 34fb8e3 into main May 29, 2026
8 checks passed

This branch was successfully deployed

1 active deployment
Preview — 33160946 Deployed May 29, 2026 by vercel[bot]
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.

reduce in lodash compatibility does not work correctly when the accumulator is null

1 participant