Last active
January 18, 2022 07:59
-
-
Save evgeniyworkbel/21468f708c0d5963bb267141b317aa5f to your computer and use it in GitHub Desktop.
Курс "Введение в программирование", Hexlet.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sumSquare = (a) => { | |
let sumSq = 0; | |
for (let i = 0; i <= a; i += 1) { | |
sumSq += i ** 2; | |
} | |
return sumSq; | |
}; | |
const squareSum = (b) => { | |
let sum = 0; | |
for (let i = 0; i <= b; i += 1) { | |
sum += i; | |
} | |
return sum ** 2; | |
}; | |
const sumSquareDifference = (n) => squareSum(n) - sumSquare(n); | |
export default sumSquareDifference; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Аналогично моему |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Сумма квадратов первых десяти натуральных чисел это 12 + 22 + 32 + ... + 10 2 = 385. | |
Квадрат суммы первых десяти натуральных чисел это (1 + 2 + 3 + ... + 10)2 = 552 = 3025. | |
Разница между квадратом суммы и суммой квадратов первых десяти натуральных чисел: 3025 − 385 = 2640. | |
Напишите функцию sumSquareDifference(), которая принимает аргумент n и возвращает разницу между квадратом суммы и суммой квадратов первых n натуральных чисел. | |
// Натуральные числа - числа, возникающие естественным образом при счёте (1, 2, 3, 4, 5, 6, 7 и так далее. | |
// Отрицательные и нецелые числа к натуральным не относят. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment