mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 15:39:42 +08:00

* 📦 NEW: Added solution for ProjectEuler-007 * 🐛 FIX: Spelling mistake fixes * 👌 IMPROVE: changed variable name from `inc` to `candidateValue` and thrown error in case of invalid input * 👌 IMPROVE: Modified the code * 👌 IMPROVE: Added test case for ProjectEuler Problem001 * 👌 IMPROVE: Added test cases for Project Euler Problem 4 * 👌 IMPROVE: auto prettier fixes --------- Co-authored-by: Omkarnath Parida <omkarnath.parida@yocket.in>
9 lines
279 B
JavaScript
9 lines
279 B
JavaScript
// https://projecteuler.net/problem=6
|
|
|
|
export const squareDifference = (num = 100) => {
|
|
let sumOfSquares = (num * (num + 1) * (2 * num + 1)) / 6
|
|
let sums = (num * (num + 1)) / 2
|
|
|
|
return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
|
|
}
|