Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 10, 2020 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/d254dd2a4775afd170d15ece3192f233 to your computer and use it in GitHub Desktop.
Save codecademydev/d254dd2a4775afd170d15ece3192f233 to your computer and use it in GitHub Desktop.
Codecademy export
// 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