-
-
Save codecademydev/8b2f085148f436f16f28013dac42ccd0 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = (specNum, strand) => { | |
return { | |
specimenNum: specNum, | |
dna: strand, | |
mutate() { | |
let index = Math.floor(Math.random() * this.dna.length); | |
let newBase = returnRandBase(); | |
while (newBase === this.dna[index]) { | |
newBase = returnRandBase(); | |
} | |
this.dna.splice(index,1,newBase); | |
return this.dna; | |
}, | |
compareDNA(aequor2) { | |
let sample1 = this.dna; | |
let sample2 = aequor2.dna; | |
let identicalCount = 0; | |
if (sample1.length === sample2.length) { | |
for (let x = 0; x < sample1.length; x++) { | |
if (sample1[x] === sample2[x]) { | |
identicalCount++; | |
} | |
} | |
} else { | |
console.log('DNA strands are not equal length. Please check your data.'); | |
} | |
let percentage = (identicalCount/sample1.length) * 100; | |
console.log(`Specimen ${this.specimenNum} and specimen ${aequor2.specimenNum} have ${Math.floor(percentage)}% DNA in common.`); | |
}, | |
willLikelySurvive() { | |
let cgBases = 0; | |
this.dna.forEach(base => { | |
if (base === 'C' || base === 'G') { | |
cgBases++; | |
} | |
}); | |
let survival = (cgBases/this.dna.length) * 100; | |
//console.log(survival); | |
if (survival >= 60) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
}; | |
} | |
const pAequorArray = []; | |
for (let x=0; x<30; x++) { | |
pAequorArray.push(pAequorFactory(x, mockUpStrand())); | |
} | |
console.log(pAequorArray.length); | |
pAequorArray.forEach(organism => {console.log(`Specimen ${organism.specimenNum} : ${organism.dna}`)}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment