Mysterious Organism - How to properly compare DNA of pAequeor

Hello everyone! I’m working on the Mysterious organism challenge and am stuck on the portion of comparing the DNA of the PAequeor organism. I’m not sure where to take the bottom most portion of the code next, any advice would be amazing!

`// 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{
number: number,
dna: dna,
mutate(){
let randomBase = Math.floor(Math.random() * this.dna.length);
let changedBase = returnRandBase();
if(randomBase === changedBase){
return this.dna
} else{
return ‘Duplicated DNA detected’
}
},
compareDNA(newPAequor){
let identical = 0;
console.log(identical)
for(let i= 0; i < newPAequor.length; i++){
for(let j = 0; j < this.dna.length; j++){
if(i === j){
identical++;
}
}
}

}
}
};`

link below is should include the instructions to the problem

https://www.codecademy.com/journeys/back-end-engineer/paths/becj-22-software-engineering-foundations/tracks/becj-22-javascript-syntax-part-ii/modules/wdcp-22-mysterious-organism-c8603589-5297-450f-9af0-366ee62f82d6/projects/mysterious-organism

you could return the proportion that’s identical, or the percentage:

    const proportion = identical / this.dna.length;
    const percent = proportion * 100;
    return percent;

proportion = amount divided by total

If you wanted to be extra safe, I guess you could divide by the maximum of the lengths instead of just one length.
const proportion = identical / Math.max(this.dna.length, newPAequor.length);

1 Like

thank you so much! I will try it out