one repo to rule them all
This commit is contained in:
commit
1559f81d30
8 changed files with 122 additions and 0 deletions
5
.idea/.gitignore
vendored
Normal file
5
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
12
.idea/codecademy.iml
Normal file
12
.idea/codecademy.iml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
10
.idea/inspectionProfiles/Project_Default.xml
Normal file
10
.idea/inspectionProfiles/Project_Default.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="true" level="TYPO" enabled_by_default="true">
|
||||
<option name="processCode" value="false" />
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/codecademy.iml" filepath="$PROJECT_DIR$/.idea/codecademy.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
7
.idea/vcs.xml
Normal file
7
.idea/vcs.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/credit-card-checker" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/mysterious-organism" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
1
credit-card-checker
Submodule
1
credit-card-checker
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit ce5ec631b235224288aa67597f005daeeaa7889a
|
74
mysterious-organism/main.js
Normal file
74
mysterious-organism/main.js
Normal file
|
@ -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())
|
||||
})
|
Loading…
Reference in a new issue