JavaScript: Sum of a square

Last update: 18 Dec 23:20
0
Students

sumSquareDifference.js

The sum of the squares of the first ten natural numbers is 12 + 22 + 32 + ... + 10 2 = 385.

The square of the sum of the first ten natural numbers is (1 + 2 + 3 + ... + 10)2 = 552 = 3025.

Hence the difference between the square of the sum and the sum of the squares of the first ten natural numbers is 3025 − 385 = 2640.

Write the sumSquareDifference() function that takes argument n and returns the difference between the square of the sum and the sum of the squares of first n natural numbers.

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests