Use exponent ** operator over Math.pow
This commit is contained in:
@ -6,7 +6,7 @@ Convert the given number into an array of digits. Use `Math.pow()` to get the ap
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const isArmstrongNumber = digits =>
|
const isArmstrongNumber = digits =>
|
||||||
(arr => arr.reduce((a, d) => a + Math.pow(parseInt(d), arr.length), 0) == digits)(
|
(arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(
|
||||||
(digits + '').split('')
|
(digits + '').split('')
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|||||||
@ -10,9 +10,7 @@ You can omit the second argument to get the sample standard deviation or set it
|
|||||||
const standardDeviation = (arr, usePopulation = false) => {
|
const standardDeviation = (arr, usePopulation = false) => {
|
||||||
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
||||||
return Math.sqrt(
|
return Math.sqrt(
|
||||||
arr
|
arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => acc + val, 0) /
|
||||||
.reduce((acc, val) => acc.concat(Math.pow(val - mean, 2)), [])
|
|
||||||
.reduce((acc, val) => acc + val, 0) /
|
|
||||||
(arr.length - (usePopulation ? 0 : 1))
|
(arr.length - (usePopulation ? 0 : 1))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user