JSFiddle - React, Tailwind, and code Playground
JavaScript
var g = 0;
var patientZero = Object.create({
gene0: "AT",
mutate: function(){
var n = ~~(Math.random()*100),
p = ["AT","TA","CG","GC"][~~(Math.random()*4)];
this["gene"+n] = p;
},
reproduce: function(){
g++;
return Object.create(this);
},
getCode: function(){
var code = "Patient generation "+g+": <br>";
for(var property in this){
code+= property+": "+String(this[property]).slice(0,15)+"<br>";
}
document.body.innerHTML += code+"<br>";
}
});
patientZero.getCode();
patientZero.mutate();
var patientUn = patientZero.reproduce();
patientUn.mutate();
var patientDeux = patientUn.reproduce();
patientDeux.mutate();
var patientTrois = patientDeux.reproduce();
patientTrois.getCode();