Files
30-seconds-of-code/snippets_archive/squareSum.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

395 B

title, tags
title tags
squareSum math,beginner

Squares each number in an array and then sums the results together.

Use Array.prototype.reduce() in combination with Math.pow() to iterate over numbers and sum their squares into an accumulator.

const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
squareSum(1, 2, 2); // 9