Hi there β. I'm Axel Espinosa from Mexico π²π½.
A Backend Developer trying to share some of his expirience in this community and on his Youtube channel. β
Hi there β. I'm Axel Espinosa from Mexico π²π½.
A Backend Developer trying to share some of his expirience in this community and on his Youtube channel. β
I think think there's an even easier solution:
I think this is more appropriate:
function shapeArea(n) {
return (1 + (n-1)*n) *2 - 1
}
Hey buddy, can you explain your solution?
Why do you think that formula ?
Did you solve it?
Yeah, that's exactly the beauty that I talk about code fights. You can learn from other solution.
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
}