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

deck: Implemented Fisher-Yates shuffling algorithm to shuffle the deck #31

Merged
merged 1 commit into from
Jun 2, 2024

Conversation

sethdivyansh
Copy link
Contributor

Fixes: #2

Description

Shuffled the deck using Fiesher-Yates algorithm

Checklist

  • I have tested these changes locally.
  • I have reviewed the code and ensured it follows the project's coding guidelines.
  • I have updated the documentation, if necessary.
  • I have assigned reviewers to this pull request.

@kuv2707
Copy link
Collaborator

kuv2707 commented Jun 1, 2024

@sethdivyansh Please resolve merge conflicts.

@sethdivyansh
Copy link
Contributor Author

@kuv2707 i have resolved the conflicted.

@kuv2707
Copy link
Collaborator

kuv2707 commented Jun 1, 2024

I suggest you write a test for this in deck.test.ts
Where you just check if the array order before and after the function call to shuffle is different.

Its not exactly required, but it would give you a chance to write unit tests for your logic.

We use the 'jest' library for testing.

The test should be in the same commit.

@sethdivyansh
Copy link
Contributor Author

@kuv2707 i have added the shuffle deck test in deck.test.ts

Copy link
Collaborator

@kuv2707 kuv2707 left a comment

Choose a reason for hiding this comment

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

Nicely done!

const orderChanged = deck.some(
(card, index) => card !== originalDeck[index]
);
expect(orderChanged).toBe(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great work detecting order change!

@kuv2707 kuv2707 merged commit ef2dc47 into shivansh-bhatnagar18:master Jun 2, 2024
5 of 6 checks passed
@kuv2707
Copy link
Collaborator

kuv2707 commented Jun 2, 2024

Merged, thanks @sethdivyansh !

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.

Implement card shuffling logic
2 participants