-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
86 lines (77 loc) · 1.99 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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 = (n, mock) => {
return ({
specimenNum: n,
dna: mock,
mutate: function() {
a = [];
a = this.dna;
b = Math.floor(Math.random() * 15);
c = returnRandBase();
if(a[b]!=c) {
a[b] = c
this.dna = a;
} else {
while(a[b]==c) {
c = returnRandBase();
}
a[b] = c
this.dna = a;
}
return this.dna;
},
compareDNA: function(pAe) {
let count = 0;
for(i=0; i < 15 ; i++) {
if(this.dna[i] == pAe.dna[i]) {
count++;
}
}
let per = Math.trunc(count/15 * 100);
console.log(`specimen #1 and specimen #2 have ${per}% DNA in common.`);
},
willLikelySurvive: function() {
let count = 0;
for(i=0; i < 15 ; i++) {
if(this.dna[i] === 'C' || this.dna[i] === 'G') {
count++;
}
}
if(count>=9){
return true;
} else {
return false;
}
}
})
}
aequor1 = pAequorFactory(1, mockUpStrand());
console.log(aequor1.dna);
//aequor1.mutate();
//console.log(aequor1.dna);
aequor2 = pAequorFactory(2, mockUpStrand());
aequor1.compareDNA(aequor2);
aequor2.compareDNA(aequor1);
console.log(aequor1.willLikelySurvive());
const instancesToStudy = [];
while(instancesToStudy.length<30) {
let newInstance = pAequorFactory(instancesToStudy.length+1, mockUpStrand());
if(newInstance.willLikelySurvive()==true) {
instancesToStudy.push(newInstance);
}
}
console.log(instancesToStudy.length);
//console.log(pAequorFactory(5,mockUpStrand()));
//console.log(pAequorFactory(6,mockUpStrand()));