繁体   English   中英

为什么以下部分会使我的浏览器崩溃?

[英]Why does the following part crash my browser?

我只是想将以下部分添加到我的代码中。 当我这样做时,我在控制台中不再得到 output 并且浏览器每次都崩溃。 如果我注释掉这部分,一切都会再次正常。 我已经测试了所有东西(缩短的循环运行,更小的数据集,..)但没有任何帮助。 有人有什么想法吗?

var index_avg_temp_array = []; // array which saves the temperature of each Cluster
index_avg_temp_array.push([]); // creates 2d array
for (id = 0; id < cluster_points; id++) {
  // id = index of the cluster

  var t_array = []; // create array / set array to 'empty'
  var amount = 0;
  var check = 0;

  // takes the id and check if day_array[].index === id
  for (day = 0; day < days_of_year; day++) {
    // 365/366 runs, day_array has 1 entry for each day

    if (day_array[day].index === id) {
      for (hour = 0; hour < 24; hour++) {
        // if true - save the hourly temperatures in hour_array

        var row = day * 24 + hour;
        var t_temp = hour_array[row].temp; // temperature of each hour
        t_array.push(t_temp);
      }
      check = 1; // if index was found for at least 1 time
      amount = amount + 1;
    }
  }
  if (check === 1) {
    // check if the index was found for at least 1 time
    for (hour = 0; hour < 24; hour++) {
      var avg = 0;
      for (counter = 0; counter < t_array.length; counter + 24) {
        var row = hour * 24 + counter;
        avg = avg + t_array[row]; // sum up each hour
      }

      var avg_hours = avg / amount; // calculate the avg of the hour
      index_avg_temp_array[id].push(avg_hours); // save the avg temperatures of each hour for each cluster point
    }
  }
}
for (counter = 0; counter < t_array.length; counter + 24) {

这会导致无限循环,因为counter永远不会更新。 counter + 24应该是counter += 24

for (counter = 0; counter < t_array.length; counter += 24) {

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM