JSFiddle - React, Tailwind, and code Playground
by Graham Fairweather
JavaScript
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function getMutations(obj) {
var mutations = [],
last = obj.genome.length - 1,
mutation,
count,
value,
pos;
for (count = 0; count <= 20; count += 1) {
pos = getRandomInt(0, last);
mutation = obj.genome.slice();
mutation[pos] = getRandomInt(0, 9);
mutations.push(mutation);
}
return mutations;
}
function concestor2() {
this.genome = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // the code to be scrambled
this.replicability = 10;
}
var venutian = new concestor2();
console.log(getMutations(venutian));