Challenge Project Mysterious Organism need help


Your team wants you to simulate P. aequor‘s high rate of mutation (change in its DNA).

To simulate a mutation, in pAequorFactory()‘s returned object, add the method .mutate().

.mutate() is responsible for randomly selecting a base in the object’s dna property and changing the current base to a different base. Then .mutate() will return the object’s dna.

For example, if the randomly selected base is the 1st base and it is 'A', the base must be changed to 'T', 'C', or 'G'. But it cannot be 'A' again.

const returnRandBase = () => { const dnaBases = ["A", "T", "C", "G"]; return dnaBases[Math.floor(Math.random() * 4)]; }; // Returns a random single strand of DNA containing 15 bases const mockUpStrand = () => { const newStrand = []; for (let i = 0; i < 15; i++) { newStrand.push(returnRandBase()); } return newStrand; }; const pAequorFactory = (number, array) => { return { specimenNum: number, dna: array, mutate() { let dnaBases = ["A", "T", "C", "G"]; let newDnaBases = []; let newChar = ""; let i = Math.floor(Math.random() * 14); //spawn position 'i' need to be changed console.log('index neet to mutate: ' + i); console.log('current dna base is: ' + this.dna[i]); newDnaBases = dnaBases.filter((element) => element !== this.dna[i]); //console.log(newDnaBases); newChar = newDnaBases[Math.floor(Math.random() * 3)]; console.log('new dna base is: ' + newChar); array.fill(newChar, i, i + 1); //change the specific position's dna base to newchar, which is randomly choose from newDnaBases without the same as it before change; console.log(this.dna); }, }; }; console.log(pAequorFactory(1, mockUpStrand())); const a = pAequorFactory(1, mockUpStrand()) a.mutate();

there are some problem i meet need someone’s guide through

  1. the biggest problem is that dna: array is randomly spawn, when i second invock try to change it’s specific position’s dna base, it will change whole dna value in mutate function, i don’t know how to make this varible keep the value outside equal to inside.

2.when i console.log the pAequorFactory function using two parameters, the third object mutate didn accept anv parameter, and it show mutate: [Function: mutate] ,is that normal?

For #1, can you provide an example of what you want to happen vs what’s happening?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.