Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 10, 2020 15:42
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/bb664ee7a2a4b5853c750e87a7cf8d43 to your computer and use it in GitHub Desktop.
Save codecademydev/bb664ee7a2a4b5853c750e87a7cf8d43 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 = (SerialNum, standDna) => {
return ({
specimenNum: SerialNum,
dna: standDna,
mutate(i){
let as = returnRandBase();
while (this.dna[i] == as) {
as = returnRandBase();
}
this.dna[i] = as;
},
compareDNA(obj) {
const specimenOne =this.dna;
const specimenTwo =obj.dna;
let coinc = 0;
for (let i=0; i < 15; i++) {
if(specimenOne[i] == specimenTwo[i]) {
coinc ++;
}
}
console.log('specimen #' + this.specimenNum +' and specimen #' +
obj.specimenNum +' have ' + coinc/15*100 + '% DNA in common')
},
willLikelySurvive() {
let counter = 0;
for (let i=0; i < 15; i++) {
if(this.dna[i] == 'C' || this.dna[i] == 'G') {
counter ++;
}
}
let survive = counter/15*100;
if (survive >= 60) {
return true;
} else {return false};
}
})
}
let dnaStore = () => {
let store = [];
for (let i=1; i < 31; i++) {
store.push(pAequorFactory(i, mockUpStrand()))
}
return store;
}
let paequorStore = dnaStore()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment