在pAequorFactory()
中,当调用该函数来创建对象时.我希望.specimenNum
对所有物体都是独一无二的.判断下面的代码
const pAequorFactory = (specimenNum, dna) => {
return {
specimenNum,
dna,
mutate() {
randomBaseIndex = Math.floor[Math.random * 15];
mutatedBase = returnRandBase();
if (this.dna[randomBaseIndex] !== mutatedBase) {
this.dna[randomBaseIndex] === mutatedBase;
return this.dna;
} else {
mutate();
}
},
compareDNA(object) {
for (i = 0; i < 15; i++) {
let j = 0;
if (object.dna[i] === this.dna[i]) {
j++;
}
let commonPercentage = (j / 15) * 100;
}
return `specimen #${this.specimenNum} and specimen #${object.specimenNum} have ${commonPercentage}% DNA in common`;
},
willLikelySurvive() {
for (i = 0; i < 15; i++) {
let j = 0;
if (this.dna[i] === "C" || this.dna[i] === "G") {
j++;
}
let survivePercentage = (j / 15) * 100;
}
return survivePercentage >= 60;
},
};
};
我还没有试过任何东西,但我正在想一种方法来比较每个物体的.specimenNum
个.