Skip to content

Instantly share code, notes, and snippets.

@nick3499
Created April 28, 2018 01:41
Show Gist options
  • Save nick3499/cd25bd7b5d6f0895eaef99f32c2e97d6 to your computer and use it in GitHub Desktop.
Save nick3499/cd25bd7b5d6f0895eaef99f32c2e97d6 to your computer and use it in GitHub Desktop.
CodeFights: shapeArea(n) Challenge
function shapeArea(n) {
init = 1;
return init + (n * ((n - 1) * 2));
}
console.log(shapeArea(4));
@nick3499
Copy link
Author

  • 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