-
Notifications
You must be signed in to change notification settings - Fork 4
#5 - Root mean square #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@@ -21,6 +21,7 @@ npm i stat-methods | |||
- [mean](#mean) | |||
- [harmonicMean](#harmonicMean) | |||
- [geometricMean](#geometricMean) | |||
- [rootMeanSquare](#rootMeanSquare) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please rename the method to rms
as set in #5 ?
#### rootMeanSquare | ||
|
||
```js | ||
rootMeanSquare(arr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename to rms
throughout all files.
* @returns {Number} the arithmetic mean of the data array | ||
*/ | ||
export function rootMeanSquare(arr) { | ||
if (min(arr) === undefined) return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you are checking here but it is a bit counter-intuitive. It is not necessary to compute the min
of the array when calculating its rms
. Could you please use this check instead ?
if (!Array.isArray(arr) || arr.length === 0) return undefined;
for (let i = 0; i < arr.length; i += 1) { | ||
arrSquareSum += arr[i] ** 2; | ||
} | ||
return Math.sqrt((arrSquareSum / arr.length)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this approach solves the problem, it does not make use of previously defined methods in the library. We could use the literal definition of the rms:
- Compute the mean of the squared values of the elements of the array;
- Compute its square root if it exists.
This would give something like this:
function rms(arr) {
const xBar = mean(arr.map(elt => elt ** 2));
return xBar === undefined ? undefined : Math.sqrt(xBar);
}
The description of root mean square may be lacking. Let me know if anything needs updating. Thanks!