-
-
Save codecademydev/d254dd2a4775afd170d15ece3192f233 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 stand of DNA containing 15 bases | |
const mockUpStrand = () => { | |
const newStrand = [] | |
for (let i = 0; i < 15; i++) { | |
newStrand.push(returnRandBase()) | |
} | |
return newStrand | |
} | |
console.log(mockUpStrand()); | |
const pAequorFactory = (numData, dnaData) => { | |
return { | |
specimenNum: numData++, | |
dna: dnaData, | |
mutate() { | |
let dnaBase = Math.floor(Math.random() * 15) | |
let baseGene = this.dna[dnaBase]; | |
let newGene = ''; | |
do{ | |
newGene = returnRandomBase; | |
}while(returnRandomBase === baseGene); | |
dna[dnaBase] = newGene; | |
return this.dna | |
}, | |
compareDNA(pAequor){ | |
let isSame = 0; | |
for(let i = 0; i < pAequor.length; i++){ | |
if(this.dna[i] === pAequor.dna[i]){ | |
isSame++; | |
} | |
} | |
isSame/=15 | |
isSame*=100 | |
console.log(`The two strands are ${isSame}% the same.`) | |
}, | |
willLikelySurvive = (thisdna) => { | |
let count = 0; | |
for(let gene in thisdna){ | |
if(gene === 'c' || gene === 'g') | |
count++; | |
} | |
count /= 15; | |
count *= 100; | |
count >= 60 ? true : false; | |
} | |
} | |
} | |
let spec1 = mockUpStrand; | |
console.log(pAequorFactory.willLikelySurvive(spec1)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment