我在添加数组的所有元素以及平均它们时遇到了问题.我该怎么做并用我目前的代码实现它?应该定义元素,如下所示.
<script type="text/javascript">
//<![CDATA[
var i;
var elmt = new Array();
elmt[0] = "0";
elmt[1] = "1";
elmt[2] = "2";
elmt[3] = "3";
elmt[4] = "4";
elmt[5] = "7";
elmt[6] = "8";
elmt[7] = "9";
elmt[8] = "10";
elmt[9] = "11";
// Problem here
for (i = 9; i < 10; i++){
document.write("The sum of all the elements is: " + /* Problem here */ + " The average of all the elements is: " + /* Problem here */ …Run Code Online (Sandbox Code Playgroud) 我有大约 300 个数组,每个数组都有 100 个 x 和 y 值数组。我想为 300 个数组的 y 值获得一个 100 均值的数组。做这个的最好方式是什么?我相信我应该使用某种减少但有点迷失。这是我到目前为止所拥有的:
let yval = cohort.map((d, i) => {
let bin = d3.nest()
.key(function(d) {
return i;
})
.rollup(function(d) {
return d;
})
.entries(d);
return bin;
});
console.log(yval);
Run Code Online (Sandbox Code Playgroud)
'cohort' 是一个对象数组。我想隔离每个群组对象中的“bins”数组。每个元素的长度为 117 个元素。对于每个 bins[i],我想从所有 bins 中得到 [i] 的平均值。我想基本上把117的300个数组变成一个117个数组。任何帮助将不胜感激!