Created
April 28, 2018 01:41
-
-
Save nick3499/cd25bd7b5d6f0895eaef99f32c2e97d6 to your computer and use it in GitHub Desktop.
CodeFights: shapeArea(n) Challenge
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
function shapeArea(n) { | |
init = 1; | |
return init + (n * ((n - 1) * 2)); | |
} | |
console.log(shapeArea(4)); |
Author
nick3499
commented
Apr 28, 2018
- init = 1
- n = 1 = 1 --> init + n * (n - 1) * 2 = 0
- n = 2 = 5 --> init + n * (n - 1) * 2 = 2
- n = 3 = 13 --> init + n * (n - 1) * 2 = 4
- n = 4 = 25 --> init + n * (n - 1) * 2 = 6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment