-
Notifications
You must be signed in to change notification settings - Fork 0
/
6-calculate.js
33 lines (26 loc) · 989 Bytes
/
6-calculate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
/* Call function from function in loop
- Implement function `average` with signature
`average(a: number, b: number): number`
calculating average (arithmetic mean).
- Implement function `square` with signature
`square(x: number): number` calculating square of x.
- Implement function `cube` with signature
`cube(x: number): number` calculating cube of x.
- Call `square` and `cube` in loop 0 to 9, pass results
to function `average` on each iteration.
Add calculation results to array and return this array
from function `calculate`.
Call functions `square` and `cube` in loop, then pass their
results to function `average`. Print what `average` returns. */
const square = (x) => x * x;
const cube = (x) => x ** 3;
const average = (a, b) => (a + b) / 2;
const calculate = () => {
const array = [];
for (let i = 0; i <= 9; i++) {
array[i] = average(square(i), cube(i));
}
return array;
};
module.exports = { square, cube, average, calculate };