Hello all!
I am running into an issue with my functions printing the results rather than just their name. I know the functions work (as far as I can tell at least) cause I can call for the functions individually and get the results needed but calling the whole factory gives me this output instead;
here is my code;
// Returns a random DNA base
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 = (specimenNum, dna) => {
return {
specimenNum,
dna,
mutate () {
const randIndex = Math.floor(Math.random() * this.dna.length);
let newBase = returnRandBase();
while (this.dna[randIndex] === newBase) {
return newBase;
};
this.dna[randIndex] = newBase;
return this.dna;
},
compareDNA (otherPAqeour) {
let count = 0;
for (let i = 0; i < this.dna.length; i++) {
if (this.dna[i] === otherPAqeour.dna[i]) {
count += 1;
}
}
console.log(`Specimen #${this.specimenNum} and Specimen #${otherPAqeour.specimenNum} have ${count * 100/this.dna.length}% DNA in common`);
},
willLikelySurvive () {
let likleySur = this.dna.filter(el => el === "C" || el === "G");
return likleySur.length / this.dna.length >= 0.6;
}
}
}
let specimenSurvive = [];
let specimenCounter = 1;
while (specimenSurvive.length <= 30) {
let newOrg = pAequorFactory(specimenCounter, mockUpStrand());
if (newOrg.willLikelySurvive()) {
specimenSurvive.push(newOrg);
}
specimenCounter++;
}
let ex1 = pAequorFactory(1, mockUpStrand());
let ex2 = pAequorFactory(2, mockUpStrand());
//console.log(ex1)
//console.log(ex1.mutate())
//console.log(ex1.compareDNA(ex2))
//console.log(ex1.willLikelySurvive())
console.log(specimenSurvive)
Any input would be greatly appreciated, I haven’t been able to find much help through articles and such.
I did also compare to the code results for the assignment and its giving the same kind of output. Makes me feel like I am missing something basic here.
thank you all in advance!