-
-
Save codecademydev/f7f40687f60f68a6718b54945b853384 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)] | |
}; | |
//console.log(returnRandBase()); | |
// 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 = (number, dnaArr) => { | |
return { | |
specimenNum: number, | |
dna: dnaArr, | |
mutate () { | |
let dnaCopy = this.dna; | |
let newDna = []; | |
const randomIndex = Math.floor(Math.random()*this.dna.length); | |
do { | |
returnRandBase(); | |
dnaCopy.splice(randomIndex, 1,returnRandBase()); | |
} while (returnRandBase() === dnaCopy[randomIndex]); | |
newDna = dnaCopy; | |
return newDna; | |
}, | |
} | |
}; | |
let creature = pAequorFactory(2, mockUpStrand()); | |
console.log(creature.dna) | |
console.log(creature.mutate()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment