You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write a function calculateTotal that takes an array of numbers, filters out the even numbers, squares the remaining numbers, and then calculates their sum.
Solution Approach:
Combine map, filter, and reduce array methods.*/
function calculateTotal(numbers) {
// Use filter to exclude even numbers
const oddNumbers = numbers.filter(number => number % 2 !== 0);
// Use map to square the remaining numbers
const squaredNumbers = oddNumbers.map(number => number * number);
// Use reduce to calculate the sum of squared numbers
const total = squaredNumbers.reduce((acc, curr) => acc + curr, 0);