嵌套在对象内部的数组,使用For循环搜索,给出未定义的结果

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (52)

我已编辑上传完整代码以在任何浏览器中运行。所有我得到的都是空白,但我正在寻找从1-80(其中有82,160种组合)的3组中的每个数字组合,我希望它输出所有这些结果的数组。但是目前,数组是空白的,但是如果我使用包含jQuery的原始代码,它只会给我最后一个值78,79和80,一遍又一遍82160次。它给了我正确的NUMBER个值,但它没有正确地填充这些值。

<!doctype html>
<html>
<head>
<title>Keno Tracker v2</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
    background-color: #f0f0f2;
    margin: 0;
    padding: 0;
    font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

}
div {
    margin: 0em auto;
    padding: 00px;
    background-color: #fff;
    border-radius: 0em;
}
a:link, a:visited {
    color: #38488f;
    text-decoration: none;
}
@media (max-width: 700px) {
    body {
        background-color: #fff;
    }
    div {
        width: auto;
        margin: 0 auto;
        border-radius: 0;
        padding: 0em;
    }
}
</style>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>

<body>
<div class="mypanel" style="" id="Heading">Last Draw Result</div>
<div class="mypanel" style="all: unset" id="draw"></div><br>
<div class="mypanel" style="all: unset" id="numbs"></div><br>
<div class="mypanel" style="all: unset" id="bon"></div><br>
<div class="mypanel" style="" id="MostDue">Most Overdue Pairs</div>
<div class="mypanel" style="all: unset" id="mosdu"></div><br>
<div class="mypanel" style="" id="MostFreq">Most Frequent Pairs</div>
<div class="mypanel" style="all: unset" id="mosfq"></div><br>
<div class="mypanel" style="display:none" id="test"></div><br>
<div class="mypanel" style="display:none" id="test2"></div><br>
  <script type=text/javascript>
  var results = new Object();
    results.Num = [12354, 12353, 12352, 12351, 12350, 12349, 12348, 12347, 12346, 12345]
    results.Picks = [[1, 2, 4, 6, 8, 9, 13, 15, 38, 39, 22, 25, 65, 44, 66, 75, 80, 34, 12, 77], [5, 2, 4, 38, 39, 7, 8, 9, 18, 14, 23, 25, 65, 44, 66, 75, 80, 34, 12, 77], [1, 2, 3, 7, 9, 10, 14, 15, 26, 21, 63, 41, 67, 71, 38, 39, 79, 32, 17, 72], [11, 12, 14, 16, 18, 19, 13, 15, 26, 27, 61, 43, 62, 72, 79, 38, 39, 37, 10, 74], [1, 2, 4, 6, 8, 9, 13, 15, 22, 25, 65, 44, 66, 75, 80, 38, 39, 34, 12, 77], [2, 3, 5, 7, 9, 10, 14, 16, 23, 26, 67, 45, 66, 76, 1, 38, 39, 35, 13, 78], [10, 22, 19, 1, 8, 9, 37, 4, 11, 5, 20, 14, 3, 35, 38, 39, 41, 74, 57, 61], [1, 2, 4, 6, 8, 9, 13, 15, 22, 25, 65, 44, 66, 75, 80, 38, 39, 34, 12, 77], [1, 2, 4, 6, 8, 9, 13, 15, 22, 25, 65, 44, 66, 75, 80, 38, 39, 34, 12, 77], [1, 2, 4, 6, 8, 9, 13, 15, 22, 25, 65, 44, 66, 75, 80, 38, 39, 34, 12, 77]]
    results.Bonus = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  var Totals = new Array();
  var temp = new Object();
  var drawsdone = 0
  var Totsdone = 0
  var displayd = 0
function getdraws() {
  var results = new Object()
     results.Num = [12354, 12353, 12352, 12351, 12350, 12349, 12348, 12347, 12346, 12345]
     results.Picks = [[1, 2, 4, 6, 8, 9, 13, 15, 38, 39, 22, 25, 65, 44, 66, 75, 80, 34, 12, 77], [5, 2, 4, 38, 39, 7, 8, 9, 18, 14, 23, 25, 65, 44, 66, 75, 80, 34, 12, 77], [1, 2, 3, 7, 9, 10, 14, 15, 26, 21, 63, 41, 67, 71, 38, 39, 79, 32, 17, 72], [11, 12, 14, 16, 18, 19, 13, 15, 26, 27, 61, 43, 62, 72, 79, 38, 39, 37, 10, 74], [1, 2, 4, 6, 8, 9, 13, 15, 22, 25, 65, 44, 66, 75, 80, 38, 39, 34, 12, 77], [2, 3, 5, 7, 9, 10, 14, 16, 23, 26, 67, 45, 66, 76, 1, 38, 39, 35, 13, 78], [10, 22, 19, 1, 8, 9, 37, 4, 11, 5, 20, 14, 3, 35, 38, 39, 41, 74, 57, 61], [1, 2, 4, 6, 8, 9, 13, 15, 22, 25, 65, 44, 66, 75, 80, 38, 39, 34, 12, 77], [1, 2, 4, 6, 8, 9, 13, 15, 22, 25, 65, 44, 66, 75, 80, 38, 39, 34, 12, 77], [1, 2, 4, 6, 8, 9, 13, 15, 22, 25, 65, 44, 66, 75, 80, 38, 39, 34, 12, 77]]
     results.Bonus = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
window.drawsdone = 1
}
function getTotals() {
  if (Totsdone == 0){
    for (a=1;a<81;a++){
      for (b=1;b<81;b++){
        if (a<b){
          for (c=1;c<81;c++){
            if (b<c){
              temp.n1 = 0
              temp.n2 = 0
              temp.n3 = 0
              temp.fq123 = 0
              temp.sin123 = 0
              temp.fq12 = 0
              temp.sin12 = 0
              temp.fq13 = 0
              temp.sin13 = 0
              temp.fq23 = 0
              temp.sin23 = 0
              temp.fq1 = 0
              temp.sin1 = 0
              temp.fq2 = 0
              temp.sin2 = 0
              temp.fq3 = 0
              temp.sin3 = 0
              for (i in results.Picks){
                if (results.Picks[i].includes(a)){
                  if (results.Picks[i].includes(b)){
                    if (results.Picks[i].includes(c)){
                      if (temp.sin123 == 0){
                        temp.sin123 = results.Num[0]-results.Num[i]
                      }
                      temp.fq123++
                      temp.n1=a
                      temp.n2=b
                      temp.n3=c
                      }
                    }
                  }
              }
              Totals.push(temp)
            }
          }
        }
      }
    }
    window.Totsdone = 1
  }
}
function display(){
  if (displayd == 0){
    console.log(Totals)
    Totals = new Array()
    window.displayd = 1
  }
}
getdraws();
setInterval(function(){
  getTotals()},2000)
setInterval(function(){
    display()},3000)
  </script>
</body>
</html>
提问于
用户回答回答于

因为你的for循环有一个硬编码的第二个条件,i<20而你的Picks数组只有10个项目,例如从第11个项目开始你就会得到undefined......

扫码关注云+社区

领取腾讯云代金券