-
-
Save davemac93/9b80ef6ca2b7d1de7faf229ae2a542ae to your computer and use it in GitHub Desktop.
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)]; | |
}; | |
// 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; | |
}; | |
function pAequorFactory(number, array) { | |
return { | |
specimenNum: number, | |
dna: array, | |
mutate() { | |
let i = 0; | |
for (let i = 0; i < array.length; ) { | |
let temp = array[i]; | |
array[i] = returnRandBase(); | |
if (array[i] !== temp) { | |
i++; | |
} | |
} | |
}, | |
compareDNA(pAequor) { | |
let sum = 0; | |
for (let i = 0; i < array.length; i++) { | |
if (array[i] === pAequor.dna[i]) { | |
sum++; | |
} | |
} | |
return `specimen #1 and specimen #2 have ${ | |
(sum * 100) / 15 | |
}% DNA in common`; | |
}, | |
willLikelySurvive() { | |
let sum = 0; | |
for (let i = 0; i < array.length; i++) { | |
if (array[i] === "C" || array[i] === "G") { | |
sum++; | |
console.log(sum); | |
} | |
} | |
if (sum > 8) { | |
return true; | |
} else { | |
return false; | |
} | |
}, | |
}; | |
} | |
let theFirstOne = pAequorFactory(1, mockUpStrand()); | |
let theFirstSecond = pAequorFactory(2, mockUpStrand()); | |
console.log(theFirstOne); | |
theFirstOne.mutate(); | |
console.log(theFirstOne); | |
console.log(theFirstSecond.compareDNA(theFirstOne)); | |
console.log(theFirstOne.willLikelySurvive()); | |
const obj = { | |
name: "Dawid", | |
}; | |
let arrayWithpAequor = []; | |
for (let i = 0; arrayWithpAequor.length < 30; i++) { | |
let temp; | |
temp = pAequorFactory(i, mockUpStrand()); | |
if (temp.willLikelySurvive()) { | |
arrayWithpAequor.push(temp); | |
} | |
} | |
console.log(arrayWithpAequor); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment