Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 6, 2020 14:28
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/9ee7eb1551413e97a5939f94c545bd0c to your computer and use it in GitHub Desktop.
Save codecademydev/9ee7eb1551413e97a5939f94c545bd0c 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(returnRandBase())
const pAequorFactory = (num, dnabase) => {
return {
specimenNum: num,
dna: dnabase,
mutate() {
const randIndex = Math.floor(Math.random() * this.dna.length);
//i like to console.log the value of randIndex at this point?
console.log(randIndex)
let newBase = returnRandBase();
while (this.dna[randIndex] === newBase) {
newBase = returnRandBase();
}
this.dna[randIndex] = newBase;
return this.dna;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment