Skip to content

fix(_internal/compareValues): place null and undefined values last when sorting#1681

Open
sukvvon wants to merge 3 commits intotoss:mainfrom
sukvvon:fix/compare-values-null-handling
Open

fix(_internal/compareValues): place null and undefined values last when sorting#1681
sukvvon wants to merge 3 commits intotoss:mainfrom
sukvvon:fix/compare-values-null-handling

Conversation

@sukvvon
Copy link
Copy Markdown
Contributor

@sukvvon sukvvon commented Apr 3, 2026

Summary

  • Add null/undefined handling to compareValues in src/_internal/compareValues.ts
  • null and undefined values are placed at the end for ascending order, at the beginning for descending order
  • undefined is placed after null (matching lodash behavior)
  • Add regression tests for both sortBy and orderBy

Fixes #1213

Test Plan

  • sortBy with null/undefined values places them at the end
  • orderBy ascending places null/undefined at the end
  • orderBy descending places undefined before null at the beginning
  • All existing sortBy/orderBy tests pass
  • Full test suite passes (4334 tests)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

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

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment Apr 3, 2026 11:20am

Request Review

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (cd553ee) to head (cfc23f9).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1681   +/-   ##
=======================================
  Coverage   99.97%   99.97%           
=======================================
  Files         497      497           
  Lines        4662     4675   +13     
  Branches     1348     1353    +5     
=======================================
+ Hits         4661     4674   +13     
  Misses          1        1           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sukvvon sukvvon marked this pull request as ready for review April 3, 2026 03:14
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.

sortBy orderBy leave nulls alone

2 participants