From 9f1683e99821a040a3e7681c195de25214fa0d0e Mon Sep 17 00:00:00 2001 From: gauvainboiche Date: Mon, 21 Jul 2025 11:50:16 +0200 Subject: [PATCH] Mysterious Organism has been shrinked out, but is now complete again --- _small_exercices/mysterious_organism.js | 39 ++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/_small_exercices/mysterious_organism.js b/_small_exercices/mysterious_organism.js index 0321084..e3cbe94 100644 --- a/_small_exercices/mysterious_organism.js +++ b/_small_exercices/mysterious_organism.js @@ -45,17 +45,45 @@ function pAequorFactory(specimenNumber, dnaArray) { compareDNA(secondDNA) { let DNAsimilarities = 0; for (let i = 0; i < this._dna.length; i++) { - if (this._dna[i] === secondDNA[i]) { + if (this._dna[i] === secondDNA.dna[i]) { DNAsimilarities++; } } - const commonDNA = DNAsimilarities / 16 * 100; // the *100 is to calculate %age - return(`The two DNA threads are ${commonDNA.toFixed(2)}% similar.`); + const commonDNA = DNAsimilarities / this._dna.length * 100; // the *100 is to calculate %age + return(`The two DNA threads of specimens numbers ${this._specimenNum} and ${secondDNA.specimenNum} are ${commonDNA.toFixed(2)}% similar.`); + }, + + willLikelySurvive() { + let survivalChances = 0; + for (let i = 0; i < this._dna.length; i++) { + if (this._dna[i] === "G" || this._dna[i] === "C") { + survivalChances++; + } + } + const totalChances = survivalChances / this._dna.length * 100; // the *100 is to calculate %age + const willSurvive = totalChances >= 60; + //console.log(`The specimen #${this._specimenNum} has a DNA composed at ${totalChances}% of C and G bases and thus will likely ${willSurvive ? "survive" : "not survive"}.`); + return willSurvive; } }; } +function pAequorLaboratory(number) { + let pAequorLab = []; + let i = 0; + while (i < number) { + let pAequor = mockUpStrand(); + let pAequorSpecimen = pAequorFactory(i+1, pAequor); + if (pAequorSpecimen.willLikelySurvive()) { + pAequorLab.push(pAequorSpecimen); + i++; + } + } + + return pAequorLab; +} + const pAequor1DNA = mockUpStrand(); const pAequor2DNA = mockUpStrand(); const pAequor1 = pAequorFactory(1, pAequor1DNA); @@ -66,4 +94,7 @@ console.log(` ${pAequor1.dna} ${pAequor2.dna}`); -console.log(pAequor1.compareDNA(pAequor2.dna)); \ No newline at end of file +console.log(pAequor1.compareDNA(pAequor2)); +pAequor1.willLikelySurvive(); +const pAequorLab1 = pAequorLaboratory(30); +console.log(pAequorLab1); \ No newline at end of file