cryptozombies-lesson-code
cryptozombies-lesson-code copied to clipboard
Fix createRandomZombie function for DNA uniqueness
Description
This pull request addresses the issue of duplicate DNA in the createRandomZombie function. When generating a random DNA for a new zombie, I noticed that the initial approach could lead to duplicate DNA values among the zombies. To ensure DNA uniqueness, I implemented a check that verifies if the generated DNA already exists in the zombies array.
Changes Made
- Added a DNA uniqueness check in the
createRandomZombiefunction to prevent duplicates. - If the initial
randDnais not unique, re-generate a newrandDnauntil uniqueness is achieved.
Testing
I have thoroughly tested the modified function with various names and verified that each new zombie created has a unique DNA.