javascript - 没有关于地图功能的信息?(不是地图)
问题描述
我对返回整数的映射函数有问题我不知道这个映射函数是什么或它的操作是什么,当我搜索时,我发现的只是需要数组的映射对象(Array.prototype.map())。///访问它但是这个函数不需要对象或变量来访问那么这个映射函数到底是什么?我觉得它在做某种健身/最大健身
编辑:实际上它确实适合/最大适合度现在我的问题是我的引擎如何知道即使我使用 ctrl + 空格不存在的地图也这样做,当我这样做或我尝试 alert(map.toString()); 查看源代码它返回本机代码,这意味着它确实存在,为什么这么多?
您可以在此链接上的示例中查看它,您会在 Population.js 类中找到它,因为它对我来说没有意义
naturalSelection() {
// Clear the ArrayList
this.matingPool = [];
let maxFitness = 0;
for (let i = 0; i < this.population.length; i++) {
if (this.population[i].fitness > maxFitness) {
maxFitness = this.population[i].fitness;
}
}
// Based on fitness, each member will get added to the mating pool a certain number of times
// a higher fitness = more entries to mating pool = more likely to be picked as a parent
// a lower fitness = fewer entries to mating pool = less likely to be picked as a parent
for (let i = 0; i < this.population.length; i++) {
alert(map.toString());
=>: let fitness = map(this.population[i].fitness, 0, maxFitness, 0,1);
let n = floor(fitness * 100); // Arbitrary multiplier, we can also use monte carlo method
for (let j = 0; j < n; j++) { // and pick two random numbers
this.matingPool.push(this.population[i]);
}
}
}
解决方案
推荐阅读
- sql - 可移植的 GROUP BY 子句规则?
- python - Seaborn catplot 与 PairGrid 相结合
- javascript - vue js中的axios将请求作为字符串而不是对象发送
- javascript - 有没有办法在变量名中使用变量?
- regex - Nginx 位置正则表达式通用
- pyspark - 如何使用 rdd.sum() 从 pyspark 中的文本文件中查找 RDD 中特定单词的总数
- c - SDL_Mixer 缺少文件
- python - 基于比较其他数据帧值生成一个带有布尔列的新数据帧
- python - 如何在 python pandas 中删除查询的键值?
- javascript - Vuetify v-progress-linear(不确定)不更新