Created
July 8, 2012 23:19
-
-
Save alexbaldwin/3073396 to your computer and use it in GitHub Desktop.
Project Euler Problem 6
This file contains hidden or 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
var squarer = function(solvingFor) { | |
var squares = []; | |
for (i=0; i <= solvingFor; i++){ | |
var squared = i * i; | |
squares.push(squared); | |
} | |
var total = 0; | |
for (i = 0; i < squares.length; i++ ) { | |
total = total + squares[i]; | |
} | |
console.log(total); | |
return total; | |
}; | |
var toSquare = function(solvingFor) { | |
var numbers = []; | |
for (i=0; i <= solvingFor; i++){ | |
numbers.push(i); | |
} | |
var total = 0; | |
for (i = 0; i < numbers.length; i++ ) { | |
total = total + numbers[i]; | |
} | |
total = total * total; | |
console.log(total); | |
return total; | |
}; | |
var squareSum = function(x) { | |
return toSquare(x) - squarer(x); | |
}; | |
console.log(squareSum(100)); | |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment