Hi all.
JS has got me feeling like the thickest person in the world.
I have got as far as what I think the mutate function should look like
(https://www.codecademy.com/paths/front-end-engineer-career-path/tracks/fecp-22-javascript-syntax-part-ii/modules/wdcp-22-mysterious-organism/projects/mysterious-organism)
But I’m not clear on 1) whether I’m testing it properly (you can see my attempts at test at the bottom), and 2) if I am indeed testing it properly, where I’m going wrong.
I’m drawing such a blank here guys, and I’d love some input.
Big love.
// Returns a random DNA base
const returnRandBase = () => {
const dnaBases = ['A', 'T', 'C', 'G']
return dnaBases[Math.floor(Math.random() * 4)]
}
// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand = []
for (let i = 0; i < 15; i++) {
newStrand.push(returnRandBase())
}
return newStrand
}
const pAequorFactory = (specimenNum, dna) => {
return {
specimenNum: specimenNum,
dna: dna,
//mutate function
mutate () {
const randIndex = Math.floor(Math.random() * this.dna.length);
let newBase = returnRandBase();
//to compare the dna base at the random index with newBase (a randomly generated base), and if they're the same, redo the step until they're not the same.
while (this.dna[randIndex] === newBase) {
newBase = returnRandBase();
}
//reassign the randIndex base as the newBase
this.dna[randIndex] = newBase;
return this.dna;
}
}
};
//variable test1
const test1 = pAequorFactory(1,mockUpStrand());
console.log(test1);
//mutate test1
test1.mutate;
console.log(test1);