gpt4 book ai didi

javascript - 只要找到相似的条目,它就应该增加

转载 作者:行者123 更新时间:2023-11-28 03:42:19 25 4
gpt4 key购买 nike

for(var i= 0; i < foundRecords.length ; i++){
var MaleChildNew=0,
MaleNew=0,
femaleChildNew=0,
femaleNew=0,
policeMaleChildNew = 0,
policefemaleChildNew=0,
policeMaleNew=0,
policefemaleNew=0,
npoliceMaleChildNew=0,
npoliceMaleNew=0,
npolicefemaleChildNew=0,
npolicefemaleNew=0;
if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
policeMaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
policefemaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
policeMaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
policefemaleNew++;
} if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
npoliceMaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
npolicefemaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
npoliceMaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
npolicefemaleNew++;
} if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
MaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
femaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
MaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
femaleNew++;
}
}

问题是它只增加在数据库末尾找到的类别并返回 1。我想要的是它应该为它发现的每个相似条目增加值并保存该值。但此代码对于所有其他变量返回 0,对于位于数据库末尾的变量返回 1。

最佳答案

您的代码将始终将变量初始化为 0,因为它们位于 for 循环内。因此,foundRecords 的每一项变量都重置为 0。因此,在 for 循环之外声明变量:

var MaleChildNew=0,
MaleNew=0,
femaleChildNew=0,
femaleNew=0,
policeMaleChildNew = 0,
policefemaleChildNew=0,
policeMaleNew=0,
policefemaleNew=0,
npoliceMaleChildNew=0,
npoliceMaleNew=0,
npolicefemaleChildNew=0,
npolicefemaleNew=0;

for(var i= 0; i < foundRecords.length ; i++){
if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
policeMaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
policefemaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
policeMaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
policefemaleNew++;
} if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
npoliceMaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
npolicefemaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
npoliceMaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
npolicefemaleNew++;
} if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
MaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
femaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
MaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
femaleNew++;
}
}

关于javascript - 只要找到相似的条目,它就应该增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48840553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com