Skip to content

Conversation

@thomasfoster
Copy link
Contributor

The description of root mean square may be lacking. Let me know if anything needs updating. Thanks!

- [mean](#mean)
- [harmonicMean](#harmonicMean)
- [geometricMean](#geometricMean)
- [rootMeanSquare](#rootMeanSquare)
Copy link
Owner

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);
Copy link
Owner

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;
Copy link
Owner

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));
Copy link
Owner

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants