“如何在Javascript中编写二维数组输入,使其看起来像这样?”

时间:2019-09-08 20:27:10

标签: javascript arrays matrix input

基本上我想做的是用Javascript开发高斯消除程序,到目前为止,当我直接在代码中输入系数矩阵时,它就可以工作,但是现在我试图让用户输入它,但是我失败了。 例如,如果我直接写

$A = [[1, 1, 1], [2, 1, 2], [1, 2, 3]];

该程序可以正常运行,但是,按照我输入矩阵的方法,它将无法正常工作。

var rows= prompt("Input the number of variables");
                var A = [];
                alert("Input the coefficients of the equations");
                for(var i = 0; i<rows; i++)
                {
                A.push([]);
                A[i].push(new Array(rows));
                for (var j = 0; j<rows; j++)
                {
                    A[i][j]= prompt()
                }
                }
            }

有没有办法正确编码?

1 个答案:

答案 0 :(得分:0)

您唯一的问题似乎是在代码末尾有一个额外的server { charset utf-8; listen 80; server_name localhost; # JupyterHub - Works perfectly on location /, not working like below. location /hub/ { proxy_pass https://127.0.0.1:9443/; } location ~ /.well-known { allow all; } # Tez - UI Works perfectly on location /, not working like below. location /tez/ { proxy_pass http://localhost:8080/tez-ui/; } # Working using this config zeppelin location /zeppelin/ { proxy_pass http://localhost:8890/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_redirect off; } location /zeppelin/ws { proxy_pass http://localhost:8890/ws; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } # Hbase Works perfectly using location / , not working like below. location /hbase/ { proxy_pass http://localhost:16010/; } # Presto Works perfectly using location / , not working like below. location /presto/ { proxy_pass http://localhost:8889/; } # Hue Works with this Config location /hue { proxy_pass http://localhost:8888; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } 。也许使用一致的段落缩进格式重新格式化将在将来阐明这种错误。请参见下面的工作代码。

}