Sum of array elements with recursion in JavaScript

Let's now not display the array elements to the console, but find their sum:

function getSum(arr) { let sum = arr.shift(); if (arr.length !== 0) { sum += getSum(arr); } return sum; } console.log(getSum([1, 2, 3]));

Given an array:

let arr = [1, 2, 3, 4, 5];

Use recursion to find the sum of the squares of this array elements.

enru