【发布时间】:2020-07-04 09:01:51
【问题描述】:
function calc_results(){
var scores = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
for (var StatementCounter = 0; StatementCounter < 29; StatementCounter++){ // 29 statements it loops trough
for (var positionCheck = 0; positionCheck < 23; positionCheck++){ // 23 parties it loops through
if(choices[StatementCounter] == subjects[StatementCounter].parties[positionCheck].position){ // if my choice is the same as the party's choice
var partyposition = getpartyposition(subjects[StatementCounter].parties[positionCheck].name);
scores[partyposition]++;
}
}
}
}
function getpartyposition(partyname){
for (var positionCheck = 0; positionCheck < 23; positionCheck++){
if(parties[positionCheck].name == partyname){
return positionCheck;
}
}
}
// these are the parties that are already connected to the string, there are actually 23 of them.
var parties = [{
name: "VVD",
},
{
name: "CDA",
},
{
name: "PVV",
}
如果我共享的代码不足,以下是链接: (其中一些是荷兰语,但任何荷兰语对于代码的完整性都不重要,因此可以忽略) https://github.com/ChancellorXeno/BackAtItAgain/blob/master/choice.js https://github.com/ChancellorXeno/BackAtItAgain/blob/master/data_array.js(各方意见决定其在scores数组中的值)
【问题讨论】:
-
你能添加一些小数据集和它想要的结果吗?
标签: javascript arrays loops multidimensional-array