Skip to content

Instantly share code, notes, and snippets.

@CLOUGH
Created April 17, 2015 15:17
Show Gist options
  • Save CLOUGH/f6a47adaafcfb52f4d29 to your computer and use it in GitHub Desktop.
Save CLOUGH/f6a47adaafcfb52f4d29 to your computer and use it in GitHub Desktop.

Revisions

  1. CLOUGH created this gist Apr 17, 2015.
    28 changes: 28 additions & 0 deletions isSquare.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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));