mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
Merge pull request #3031 from jspsych/fix-datacolumn-mean-2905
Change `DataColumn.mean()` to ignore `null` and `undefined` values
This commit is contained in:
commit
c3eb8e54c0
5
.changeset/forty-weeks-walk.md
Normal file
5
.changeset/forty-weeks-walk.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"jspsych": major
|
||||
---
|
||||
|
||||
Changed the behavior of `DataColumn.mean()` to exclude `null` and `undefined` values from the calculation, as suggested in #2905
|
@ -10,7 +10,18 @@ export class DataColumn {
|
||||
}
|
||||
|
||||
mean() {
|
||||
return this.sum() / this.count();
|
||||
let sum = 0;
|
||||
let count = 0;
|
||||
for (const value of this.values) {
|
||||
if (typeof value !== "undefined" && value !== null) {
|
||||
sum += value;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
median() {
|
||||
|
Loading…
Reference in New Issue
Block a user