My solution to the challenge
My snippet below!
this is my code !
Hereβs my version. Once again, likely a little slower than the solution code.
Here is my solution, i do believe it needs some work on the output tho as it only outputs the function name rather than the actual values.
git: GitHub - eliazar-lopez/Mysterious_Organiism_Challenge: CodeCademy Challenge project in JavaScript
My final code (though I didnβt do the extra challenges)
it seems i do not have the share icon as indicated here
My complete version of the project.
Appreciate yβall also if you guys comment for better changes.
// 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= (specimenNum, dna) => {
return {
specimenNum:specimenNum,
dna:dna,
mutate() {
let i=Math.floor(Math.random()*15)
let mutateGene=dna[i]
let newGene=returnRandBase()
if (mutateGene!== newGene) {
dna[i]=newGene;
}
},
compareDNA(otherObj) {
let count=0;
otherObj.dna;
this.dna;
for (i=0; i < this.dna.length; i++) {
if(this.dna[i] === otherObj.dna[i]) {
count++
}
//console.log(count)
}
//console.log(this.dna.length)
//console.log(count)
let percent= (count/(this.dna.length)) * 100
//console.log(percent)
console.log(specimen #1 and specimen #2 have ${percent}% DNA in common
)
},
willLikelySurvive() {
let count=0;
for (i=0; i<this.dna.length; i++) {
if(this.dna[i]===βCβ || this.dna[i]===βGβ) {
count++
}
}
let percent= (count/(this.dna.length)) * 100
if(percent > 60) {
return true
}
return false
}
}
}
//console.log(mockUpStrand())
let kitty=pAequorFactory(005, [βCβ, βAβ, βTβ, βTβ])
let puppy=pAequorFactory(015, [βTβ, βAβ, βGβ, βGβ])
let ex1 = pAequorFactory(025, [βAβ, βCβ, βTβ, βGβ, βCβ, βTβ, βCβ, βAβ, βTβ, βCβ, βAβ, βCβ, βTβ, βTβ, βGβ])
let ex2 = pAequorFactory(035, [βCβ, βAβ, βTβ, βTβ, βTβ, βCβ, βGβ, βAβ, βCβ, βGβ, βCβ, βTβ, βAβ, βTβ, βAβ])
let Courtney = pAequorFactory(045, [βCβ, βGβ, βGβ, βGβ, βCβ, βCβ, βGβ, βCβ, βCβ, βGβ, βCβ, βTβ, βAβ, βTβ, βAβ])
kitty.mutate()
//console.log(kitty)
ex1.compareDNA(ex2)
console.log(Courtney.willLikelySurvive())
let studyGroup=
let x=100
for(let i=0; i<30; i++) {
let y=mockUpStrand();
studyGroup.push(pAequorFactory(x,y))
x++
}
console.log(studyGroup)
This is my completed code. It took quite a while and I had to figure out ways to do steps 4, and 5 because they seemed a bit confusing. I really enjoyed this project overall though
Hey, this is my version ` 1. The project involves simulating the DNA of a fictional organism called *P. aequor*. Each organism has a unique DNA sequence made up of 15 bases, represented by the letters βAβ, βTβ, βCβ, and βGβ. The goal is to create and analyze these organisms using a series of functions and methods.
Key Components
1. Factory Function:
The `pAequorFactory` function creates an organism with a unique identifier and a DNA sequence. It returns an object with properties and methods to manipulate and analyze the DNA.
2. DNA Mutation:
The `.mutate()` method randomly changes one base in the DNA to simulate mutation, ensuring the new base is different from the original.
3. DNA Comparison:
The `.compareDNA()` method compares the DNA of two organisms and calculates the percentage of identical bases in the same positions.
4. Survival Likelihood:
The `.willLikelySurvive()` method checks if an organism is likely to survive based on having at least 60% of its DNA made up of βCβ or βGβ bases.
5. Complementary DNA:
The `.complementStrand()` method generates the complementary DNA strand, where βAβ pairs with βTβ and βCβ pairs with βGβ.
6. Creating Surviving Organisms:
A function generates 30 organisms that are likely to survive, based on their DNA composition.
Purpose
This project helps understand genetic concepts like mutation, DNA comparison, and survival likelihood in a simplified and interactive way. It uses programming to simulate biological processes, making it a fun and educational exercise in both biology and coding.`
// 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;
};
// Returns an object that contains the properties specimenNum and dna
function pAequorFactory(num, arr) {
return {
specimenNum: num,
dna: arr,
mutate() {
const dnaBases = ["A", "T", "C", "G"];
const randomIndex = Math.floor(Math.random() * this.dna.length);
let newBase = this.dna[randomIndex];
// Ensure the new base is different from the current base
while (newBase === this.dna[randomIndex]) {
newBase = dnaBases[Math.floor(Math.random() * dnaBases.length)];
}
// Replace the base at the random index
this.dna[randomIndex] = newBase;
return this.dna;
},
// Comparing the current pAequorβs .dna with the passed in pAequorβs .dna and compute how many bases are identical and in the same locations.
compareDNA(otherPAequor) {
let identicalCount = 0;
for (let i = 0; i < this.dna.length; i++) {
if (this.dna[i] === otherPAequor.dna[i]) {
identicalCount++;
}
}
const percentage = (identicalCount / this.dna.length) * 100;
console.log(
`specimen #${this.specimenNum} and specimen #${
otherPAequor.specimenNum
} have ${percentage.toFixed(2)}% DNA in common.`
);
},
willLikelySurvive() {
let countCG = 0;
for (let base of this.dna) {
if (base === "C" || base === "G") {
countCG++;
}
}
const percentageCG = (countCG / this.dna.length) * 100;
return percentageCG >= 60;
},
};
}
const createSurvivingPAequor = () => {
const survivingPAequor = [];
let specimenNum = 1;
while (survivingPAequor.length < 30) {
const newOrganism = pAequorFactory(specimenNum, mockUpStrand());
if (newOrganism.willLikelySurvive()) {
survivingPAequor.push(newOrganism);
}
specimenNum++;
}
return survivingPAequor;
};
My solution:
That was a nice challenge. It did take me much longer than 30 minutes though. I donβt think the time indicator is accurate. Here is my code: MysteriousOrganismChallenge/main.js at main Β· FDeveloperTest/MysteriousOrganismChallenge Β· GitHub