Skip to content

fix(nearest): allow returning all colors for a finite count#273

Open
spokodev wants to merge 1 commit into
Evercoder:mainfrom
spokodev:fix/nearest-caps-results-below-count
Open

fix(nearest): allow returning all colors for a finite count#273
spokodev wants to merge 1 commit into
Evercoder:mainfrom
spokodev:fix/nearest-caps-results-below-count

Conversation

@spokodev

@spokodev spokodev commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

nearest() capped the result count at arr.length - 1, so requesting a count equal to the palette size silently dropped the farthest match even though the docs say it finds the n nearest colors. nearest includes the query color itself, so the cap has no justification. For a five-color palette, nearest(palette)('orange', 5) returned four colors instead of five.

This caps at arr.length so a finite count can return every color. Infinity already returned all colors and is unchanged. Adds a test.

The result count was capped at one below the number of colors, so
requesting a count equal to the array length dropped the farthest
match. Cap at the array length instead.
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.

1 participant