我必須根據inputArray和factorArray進行一些計算並創建第三個數組outputArray。你可以看到基於標的財產outputArray性標誌和noOfStudents caclucations部分基於Javascript中兩個對象數組計算的對象數組
var inputArray = [
{ subject: 'Maths', marks: '40', noOfStudents: '5' },
{ subject: 'Science', marks: '50', noOfStudents: '16' },
{ subject: 'History', marks: '35', noOfStudents: '23' },
{ subject: 'Science', marks: '65', noOfStudents: '2' },
{ subject: 'Maths', marks: '30', noOfStudents: '12' },
{ subject: 'History', marks: '55', noOfStudents: '20' }
];
var factorArray = [
{ subject: 'History', marks: '500', noOfStudents: '200' },
{ subject: 'Maths', marks: '200', noOfStudents: '150' },
{ subject: 'Science', marks: '300', noOfStudents: '100' }
];
var outputArray = [
{ subject: 'Science', marks: '300-(50+65)', noOfStudents: '100-(16+2)' },
{ subject: 'Maths', marks: '200-(40+30)', noOfStudents: '150-(5+12)' },
{ subject: 'History', marks: '500-(35+55)', noOfStudents: '200-(23+20)' }
];
我需要的解決方案擴展到我剛纔的問題:https://stackoverflow.com/a/37481705
是'subject'在'factorArray'獨特之處? – IMTheNachoMan
那麼,你的問題是什麼?你堅持的是什麼?你做了什麼來試圖解決這個問題? –
如果結果看起來像'marks:'300-(50 + 65)',或者你需要計算結果'marks:'185''嗎? –