DEV Community

Discussion on: The challenge to make a shape area calculation in CodeSignal

Collapse
 
equiman profile image
Camilo Martinez

Yeah, that's exactly the beauty that I talk about code fights. You can learn from other solution.

Collapse
 
kikeflowers profile image
kikeflowers • Edited

I found this solution and just replaced the variables

function shapeArea(n) {
return 1 + 2 * n * (n-1)
//1 + 2 * 4 * (3) = 3*4=12*2=24+1=25
//1 + 2 * 3 * (2) = 2*3=6*2=12+1=13
//1 + 2 * 2 * (1) = 1*2=2*2=4+1=5
//1 + 2 * 1 * (0) = 0*1*=0*2=0+1=1
}