1.0.0 • Published 2 years ago
@flawless_frog/universal-perimeter v1.0.0
perimeter = (shape) =>{ sum = 0
start_point = shape0 for ( i = 1 ; i < shape.length; i++){
point = shape[i]
side = Math.sqrt(Math.pow(point.x - start_point.x, 2) + Math.pow(point.y - start_point.y, 2))
start_point = point
sum += side
}
start_point = shape0 point = shape.pop()
side = Math.sqrt(Math.pow(point.x - start_point.x, 2) + Math.pow(point.y - start_point.y, 2))
sum += side console.log(sum)
}
1.0.0
2 years ago