Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): allow shuffle to return first element in first index #3070

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

gracetxgao
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

randomSubset with length 1 never returns the first element. This is because shuffle makes it impossible for the first element of the shuffled array to be the same as the first element of the original array, and randomSubset slices the shuffled array up to length to return the subset.

Fixes: #1780

What is the new behavior?

shuffle can now potentially return an array with the first element being the first element of the original array, so calling randomSubset with length 1 can return the first element.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@gracetxgao gracetxgao requested review from a team as code owners September 17, 2024 02:12
Copy link
Member

@damienwebdev damienwebdev left a comment

Choose a reason for hiding this comment

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

@gracetxgao this needs a rebase. It includes commits from #3056

Additionally, can you add a test covering the empty array case as well as the single-element case?

Copy link
Member

@damienwebdev damienwebdev left a comment

Choose a reason for hiding this comment

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

lgtm

@damienwebdev damienwebdev merged commit 7d07b8a into graycoreio:develop Sep 17, 2024
51 checks passed
@gray-bot gray-bot mentioned this pull request Sep 17, 2024
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.

[BUG] randomSubset does not include first element
2 participants