// 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
}
let othersOrg = mockUpStrand(); // We are get the DNA from others company’s
// New function call pAequorFactory
const pAequorFactory = (num, arrDNA) => {
return {
specimenNum: num,
dna: arrDNA,
// Simulate a mutation randomly with a different base
mutate() {
// I can solve this part with help from Newvolante
// This form we are get a base random base to comparate with the original
const baseIndex = Math.floor(Math.random() * this.dna.length);
let randomBase = returnRandBase();
// Give a random base to a new variable to comparate
while (this.dna[baseIndex] === randomBase) {// The loop until base is different from old base
randomBase = returnRandBase(); // Logs if randomBase and old base are equal
}
this.dna[baseIndex] = randomBase; // Replacing the base with a random one
return this.dna; // Return the random base
},
// Comparate the DNA sequence of different organisms
compareDNA() {
// I can solve this part with help from codecademydev
let sequenceFamiliar = 0; // Save the familiarity
let othersOrganism = othersOrg; // We are attach other DNA
let ourDNA = this.dna; // Assigned our DNA
for (let y = 0; y < ourDNA.length; y++) { // We will cross our DNA
for (let x = 0; x < othersOrganism.length; x++) { // We will cross others DNA
if (y === x && ourDNA[y] === othersOrganism) {
// We are comparate positions and the same item if is true save
sequenceFamiliar++; // Count how many letters is equals
// console.log(This our DNA ${ourDNA[y]}
);
// console.log(This others DNA ${othersOrganism[x]}
);
}
}
}
// console.log(This is our DNA ${ourDNA}.
);
// console.log(This others DNA ${othersOrganism}.
);
// console.log(This is the familiar ${sequenceFamiliar}
);
console.log(Specimen #1 and specimen #2 have ${Math.floor(100 / 15 * sequenceFamiliar)}% DNA in common.
);
// With ${Math.floor(100 / 15 * sequenceFamiliar)} we are get the rate familiarity
},
// We are get DNA ‘C’ or ‘G’ if is equals to 60% it’s true or false if is less
willLikelySurvive() {
let countSV = 0;
for (let f = 0; f < this.dna.length; f++) { // Use this form because we are pass the info with a new var this was change
if (this.dna[f] === ‘C’ || this.dna[f] === ‘G’) {
countSV++;
}
}
const surviveRate = Math.floor(100 / 15 * countSV);
return surviveRate >= 60 ? true : false;
},
}
};
/* Other form but this get the 30 DNA without method willLikelySurvive()
let studyDNA = ;
for (let syDNA = 0; syDNA <= 30; syDNA++) {
studyDNA.push(pAequorFactory(syDNA, mockUpStrand()));
}
console.log(studyDNA); /
// Create a new function to get the better DNA
const validDNA = () => {
// I can solve this part with help from codecademydev
let valid = []; // Valid storage the values it’s true
let id = 0;
// The loop while finished when the array finished to 30 this begin in 0
while (valid.length < 30) {
let arrValid = pAequorFactory(id, mockUpStrand()); // We are storage the DNA in a new variable
if (arrValid.willLikelySurvive() === true) { // Only we are get the DNA is better
valid.push(arrValid);
}
id++;
}
return valid;
};
console.log(validDNA());
/ Print the results */
console.log(pAequorFactory(1, mockUpStrand())); // Without method MUTATE
console.log(pAequorFactory(1, mockUpStrand()).mutate()) // With method MUTATE
console.log(pAequorFactory(1, mockUpStrand()).compareDNA()); // Print the results of compareDNA()
console.log(pAequorFactory(1, mockUpStrand()).willLikelySurvive()); // Print true or false if the DNA is more C and G