I am trying to create a factory function that comes with a mutate() method that takes a random element in the object.dna property and change it to a random base from bases = ['A', 'T', 'C', 'G']. However, the element randomly selected from object.dna has to be changed to an different base, and it cannot remain the same.
const pAequorFactory = (specimenNum, dna) => {
return {
specimenNum,
dna,
mutate() {
const bases = ['A', 'T', 'C', 'G'];
let selectedBase = this.dna[Math.floor(Math.random()*this.dna.length)];
let randomBase
do {
randomBase = bases[Math.floor(Math.random()*bases.length)];
// console.log(randomBase);
} while (selectedBase === randomBase);}
}
}
const a = [
'G', 'C', 'A', 'T',
'C', 'G', 'G', 'A',
'C', 'G', 'G', 'T',
'T', 'A', 'G'
]
let b =pAequorFactory(17, a)
b.mutate;
console.log(b.dna);
I ran the code above and expected a random element in b.dna to change, but it didn't.