-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem46.js
More file actions
29 lines (18 loc) · 669 Bytes
/
problem46.js
File metadata and controls
29 lines (18 loc) · 669 Bytes
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
/* Write an arrow function where it will do the following:**
1. Square each array element
2. Calculate the sum of the squared elements
3. Return the average of the sum of the squared elements
**Print the result. */
const complexMathOperation = nums => {
let sumOfAllNumsSqure = 0;
for(const num of nums){
const squareOfNum = num * num;
sumOfAllNumsSqure = sumOfAllNumsSqure + squareOfNum ;
}
const averageOfAllNumsTotal = sumOfAllNumsSqure / nums.length;
return averageOfAllNumsTotal;
}
const numbers = [10, 13, 45, 46];
/* const numbers = [2, 3, 4]; */
const result = complexMathOperation(numbers);
console.log(result.toFixed(2));