Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created January 23, 2021 03:53
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/7e7ab12293d7715ed3c84f09552fe1f2 to your computer and use it in GitHub Desktop.
Save codecademydev/7e7ab12293d7715ed3c84f09552fe1f2 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
}
const pAequorFactory = (number, dna) => {
const mutate = () => {
let randomNum = Math.floor(Math.random() * 16);
let newBase = returnRandBase();
if (this.dna[randomNum] === newBase) {
newBase = returnRandBase();
} else {
this.dna[randomNum] = newBase;
}
return this.dna;
}
return {
specimenNum: number,
dna: dna,
mutate
}
}
let pA1 = pAequorFactory(1, mockUpStrand());
console.log(pA1.dna);
console.log(pA1.mutate());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment