I am interested in developing a Statistics class that can handle 25 inputs (or possibly more or less) and perform calculations to find values such as mean, median, mode, range, variance, and standard deviation.
Is it possible to achieve something like this?
class Solution{
constructor(...inputs){
[this.input1, this.input2, ...rest] = inputs;
}
}
When working with an array of arguments in the methods, do I need to use "map" or "forEach"? If so, how would I implement it? Like this:
mean(...inputs){
let sum=0;
inputs.forEach((element)=>{
sum+= element;
})
return sum/inputs.length;
}
The expected output should resemble the following:
ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]
console.log('Count:', statistics.count()) // 25
console.log('Sum: ', statistics.sum()) // 744
console.log('Min: ', statistics.min()) // 24
console.log('Max: ', statistics.max()) // 38
console.log('Range: ', statistics.range() // 14
console.log('Mean: ', statistics.mean()) // 30
console.log('Median: ',statistics.median()) // 29
console.log('Mode: ', statistics.mode()) // {'mode': 26,}
console.log('Variance: ',statistics.var()) // 17.5
console.log('Standard Deviation: ', statistics.std()) // 4.2
console.log('Variance: ',statistics.var()) // 17.5
console.log('Frequency Distribution: ',statistics.freqDist()) // [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, sign38), (4.0, 29), (4.0, 25)]
// The output should be similar to this:
console.log(statistics.describe())
Count: 25
Sum: 744
Min: 24
Max:...38
Range:..14
Mean:...30
Median:29
Mode:...(26, 5)
Variance:.17.5
Standard Deviation:.4.2
Frequency Distribution:[(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)].
I am still exploring how to pass a variable length of arguments to my class's constructor method.