Sum of Squares of Special Elements

EasyArrayEnumeration

Solution

export function sumOfSquares(nums: number[]): number {
  const n = nums.length;
  return nums.reduce((acc, num, i) => (n % (i + 1) === 0 ? acc + num ** 2 : acc), 0);
}