-
-
Save codecademydev/dac90b839b1c2ded2856a20148ccbd4f to your computer and use it in GitHub Desktop.
// 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 | |
} | |
let currentDna = mockUpStrand(); | |
const pAequorFactor = (number, array) => { | |
return { | |
specimenNum: number, | |
dna: array, | |
mutate () { | |
let randomIndex = Math.floor(Math.random() * this.dna.length) | |
let newBase = returnRandBase(); | |
while (this.dna[randomIndex] === newBase) { | |
newBase = returnRandBase(); | |
} | |
this.dna[randomIndex] = newBase; | |
return this.dna; | |
}, | |
compareDna () { | |
let example1 = this.dna; | |
let example2 = currentDna; | |
let score = 0; | |
for (let j = 0; j < example1.length; j++) { | |
for (let k = 0; k < example2.length; k++) { | |
if (j === k && example1[j] === example2[k]) { | |
score = score + 1; | |
} | |
} | |
} | |
console.log(`Specimen 1 and Specimen 2 have ${Math.floor(100 / 15 * score)}% DNA in common`) | |
}, | |
willLikelySurvive () { | |
let dnaScore = 0; | |
const survivedStrand = []; | |
for (let l = 0; l < this.dna.length; l++) { | |
if (this.dna[l] === 'C' || this.dna[l] === 'G') { | |
dnaScore = dnaScore + 1; | |
} | |
} | |
if (Math.floor(100 / 15 * dnaScore) > 60) { | |
survivedStrand.push(this.dna); | |
} | |
return console.log(survivedStrand); | |
} | |
} | |
}; | |
console.log (pAequorFactor(2, mockUpStrand())); | |
// Returns a random DNA base
const returnRandBase = () => {
const dnaBases = ['A', 'T', 'C', 'G']
return dnaBases[Math.floor(Math.random() * 4)]
}
// Returns a random single strand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand = []
for (let i = 0; i < 15; i++) {
newStrand.push(returnRandBase())
}
return newStrand
}
const pAequorFactory= (_number, array)=>{
return {
specimenNum: _number,
dna: mockUpStrand(),
mutate(){
let mutagenicB= returnRandBase();
let nonmutatedG=pAequorFactory.dna;
for(let i=0; i<mutatedG.length; i++){
pointM=Math.floor(Math.random()*mutatedG.length);
removedB=nonmutatedG.slice(pointM, pointM+1);
if(mutagenicB===removedB){
let mutagenicB= returnRandBase();
let nonmutatedG=pAequorFactory.dna;
for(let i=0; i<mutatedG.length; i++){
pointM=Math.floor(Math.random()*mutatedG.length);
removedB=nonmutatedG.slice(pointM, pointM+1);}
}else {
return nonmutatedG.splice(pointM, mutagenicB);
}
}
},
compareDNA(pAequor2) {
let counter=0;
pAequor1= pAequorFactory(1, pAequorFactory.dna);
pAequor2= pAequorFactory(2, pAequorFactory.dna);
for(let i=0; i<pAequor1.dna.length; i++) {
if(pAequor1.dna[i]===pAequor2.dna[i])
{
counter= counter+1;
}
}
let percentBasesInCommon= (100/pAequor1.dna.length)*counter;
console.log(pAequor1);
console.log(pAequor2);
console.log(counter);
return percentBasesInCommon.toFixed(2) + '%';
},
willLikelySurvive() {
let counter= 0;
for(let i=0; i<pAequor1.dna.length; i++) {
if(pAequor1.dna[i]==='C' || pAequor1.dna[i]==='G') {
counter= counter+1;
}
console.log(counter);
}
// 60% is same as 0.6
if(counter=== (0.6*pAequor1.dna.length) || counter>(0.6*pAequor1.dna.length)){
return true;
}else {
return false;
}
}
}
}
pAequor1= pAequorFactory(1, pAequorFactory.dna);
pAequor2= pAequorFactory(2, pAequorFactory.dna);
console.log(pAequor1.compareDNA(pAequor2));
console.log(pAequor1.willLikelySurvive());
const research= [];
for(let counter=1; counter<31; counter++){
research.push(pAequorFactory(counter, pAequorFactory.dna));}
console.log(research);
awesome.great job !!!