cryptozombies-lesson-code icon indicating copy to clipboard operation
cryptozombies-lesson-code copied to clipboard

Fix createRandomZombie function for DNA uniqueness

Open xyz899 opened this issue 2 years ago • 0 comments

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 createRandomZombie function to prevent duplicates.
  • If the initial randDna is not unique, re-generate a new randDna until 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.

xyz899 avatar Aug 07 '23 09:08 xyz899