From 1559f81d30c93a52fceb12f76df1ea74246da9fa Mon Sep 17 00:00:00 2001 From: marleyrae Date: Thu, 22 Jun 2023 22:01:52 -0700 Subject: [PATCH] one repo to rule them all --- .idea/.gitignore | 5 ++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ .idea/codecademy.iml | 12 ++++ .idea/inspectionProfiles/Project_Default.xml | 10 +++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 7 ++ credit-card-checker | 1 + mysterious-organism/main.js | 74 ++++++++++++++++++++ 8 files changed, 122 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/codecademy.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 160000 credit-card-checker create mode 100644 mysterious-organism/main.js diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/codecademy.iml b/.idea/codecademy.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/codecademy.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..97d68e3 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c43b02e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..e7eb51c --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/credit-card-checker b/credit-card-checker new file mode 160000 index 0000000..ce5ec63 --- /dev/null +++ b/credit-card-checker @@ -0,0 +1 @@ +Subproject commit ce5ec631b235224288aa67597f005daeeaa7889a diff --git a/mysterious-organism/main.js b/mysterious-organism/main.js new file mode 100644 index 0000000..2f78028 --- /dev/null +++ b/mysterious-organism/main.js @@ -0,0 +1,74 @@ +// 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 +} + +const pAequorFactory = function (id, DNA) { + return { + specimenNum: id, + dna: DNA, + + mutate() { + const baseToChange = Math.floor(Math.random() * this.dna.length) + let mutation + + do { + mutation = returnRandBase() + } while (mutation === this.dna[baseToChange]) + + this.dna[baseToChange] = mutation + }, + + compareDNA(other) { + let common = 0 + + for (let i = 0; i < this.dna.length; i++) { + if (this.dna[i] === other.dna[i]) { + common++ + } + } + + const percentage = (common / this.dna.length) * 100 + console.log(`Specimen #${this.specimenNum} and specimen` + + ` #${other.specimenNum} have ${percentage}% DNA in common`) + }, + + willLikelySurvive() { + let goodBases = 0 + + this.dna.forEach((base) => { + if (base === 'C' || base === 'G') { + goodBases++ + } + }) + + return (goodBases / this.dna.length) >= 0.6 + }, + } +} + +let samples = [] +let id = 1 + +while (samples.length < 30) { + samples.push(pAequorFactory(id, mockUpStrand())) + id++ +} + +samples.forEach((sample) => { + while (!sample.willLikelySurvive()) { + sample.mutate() + } + + console.log(sample.specimenNum, sample.dna, sample.willLikelySurvive()) +})