Created
May 3, 2020 10:50
-
-
Save DmitryOlkhovoi/d4dcf3eb7193687abf3a6ef34df5633a to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/mujivut
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const random = require('./random'); | |
class DNA { | |
constructor(length, dna = null) { | |
// Main | |
this.length = length; | |
this.genes = dna ? dna.genes : this.getRandomGenes(this.length); | |
// Additional | |
this.fitness = 0; | |
} | |
getRandomGenes(length) { | |
return new Array(length) | |
.fill(0) | |
.map(() => random.getRandomInt(32, 128)); | |
} | |
updateLength(length) { | |
if (length <= this.genes) { | |
throw 'Error'; | |
} | |
this.genes = [...this.genes, this.getRandomGenes(length - this.genes.length)]; | |
} | |
} | |
module.exports = DNA; | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const random = require('./random'); | |
class DNA { | |
constructor(length, dna = null) { | |
// Main | |
this.length = length; | |
this.genes = dna ? dna.genes : this.getRandomGenes(this.length); | |
// Additional | |
this.fitness = 0; | |
} | |
getRandomGenes(length) { | |
return new Array(length) | |
.fill(0) | |
.map(() => random.getRandomInt(32, 128)); | |
} | |
updateLength(length) { | |
if (length <= this.genes) { | |
throw 'Error'; | |
} | |
this.genes = [...this.genes, this.getRandomGenes(length - this.genes.length)]; | |
} | |
} | |
module.exports = DNA;</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const random = require('./random'); | |
class DNA { | |
constructor(length, dna = null) { | |
// Main | |
this.length = length; | |
this.genes = dna ? dna.genes : this.getRandomGenes(this.length); | |
// Additional | |
this.fitness = 0; | |
} | |
getRandomGenes(length) { | |
return new Array(length) | |
.fill(0) | |
.map(() => random.getRandomInt(32, 128)); | |
} | |
updateLength(length) { | |
if (length <= this.genes) { | |
throw 'Error'; | |
} | |
this.genes = [...this.genes, this.getRandomGenes(length - this.genes.length)]; | |
} | |
} | |
module.exports = DNA; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment