If I were to place a bet, I would say that you have some undefined
lurking around.
This problem really depends on your input data and therefore on the contents of this.model.processed
.
On a general basis, a number of calculations in JavaScript can result in NaN
.
Some typical cases are:
- "A"/0
- "A"/"B"
- 0/"A"
- 0/0
- NaN/0
- 0/NaN
- NaN/NaN
- undefined/10
- 1/undefined
However, in your specific case it's also possible that the problem is not in the division but in the sum within the (val.trimA+val.trimB+val.trimC+val.flowerOilGrade/val.flowers)
expression.
In particular, you can have NaN
also for:
And all similar expressions.
I would recommend putting some breakpoints around and verify the individual values. If the amount of entries doesn't lend itself to breakpoints, try and put some console.log
on those same values and then check them. This should allow you to pinpoint the specific value (or values) that cause the output to be NaN
.
Also, once you found the issue, you will probably want to cover your base by adding unit tests working against both valid and invalid input data.