[Angular] 複選題且取複選選項分數最高分的寫法
// 0190 複選題
calculatekyc0190Score() {
let kyc0190Score = 0;
const kyc0190Value = this.formDataService.serviceFormGroup.controls.counterkyc.get(
'kyC0190',
).value;
if (kyc0190Value) {
if (kyc0190Value.length > 0) {
const [...kyc0190Array] = kyc0190Value;
for (const i in kyc0190Array) {
if (kyc0190Array[i] === 'a1') {
kyc0190Array.splice(i, 1, 3);
} else if (kyc0190Array[i] === 'a2') {
kyc0190Array.splice(i, 1, 3);
} else if (kyc0190Array[i] === 'a3') {
kyc0190Array.splice(i, 1, 4);
} else if (kyc0190Array[i] === 'a4') {
kyc0190Array.splice(i, 1, 4);
}
}
// 因為是複選題取最高分
kyc0190Score = Math.max.apply(null, kyc0190Array);
}
}
return kyc0190Score;
}
留言
張貼留言