Skip to content

Instantly share code, notes, and snippets.

@CLOUGH
Created April 17, 2015 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CLOUGH/f6a47adaafcfb52f4d29 to your computer and use it in GitHub Desktop.
Save CLOUGH/f6a47adaafcfb52f4d29 to your computer and use it in GitHub Desktop.
Check to see if a list of coords form a square
var isSquare = function(cords){
console.log(cords);
for(var i=0;i<cords.length-1;i++){
var currentVector = Math.pow(cords[i].x-cords[i+1].x,2) + Math.pow(cords[i].y-cords[i+1].y,2);
if(i==0){
previousVector = currentVector;
console.log(currentVector, previousVector);
}
else{
console.log(currentVector, previousVector);
if( currentVector*2 == previousVector || currentVector/2 == previousVector || currentVector==previousVector){
} else{
return false;
}
}
}
return true;
}
var cords = [
{ x:8, y:3 },
{ x:7, y:8 },
{ x:2, y:7 },
{ x:3, y:2}
];
console.log('Is Funtion: '+isSquare(cords));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment