Sum of squares

Report a typo

The function sumOfSquares accepts an array of numbers and returns the sum of squared elements of an array as a promise. You need to handle the promises using the async/await syntax inside the try/catch block. If the promise is fulfilled, the sum will be logged into the console; otherwise, the error is logged into the console.

You do not need to call the calculateSum function. It's handled internally and called two times with different input arrays.

Sample Input 1:

Sample Output 1:

55
90
Write a program in JavaScript
async function sumOfSquares(numbers) {
const squares = numbers.map((number) => number * number);
const sum = squares.reduce(
(accumulator, currentValue) => accumulator + currentValue,
0
);
return sum;
}

// Write code below this line

async function calculateSum(arrayOfNumbers) {
try {
...await...
console.log(sum);
}
...

}

// Write code above this line
___

Create a free account to access the full topic