Skip to content

Instantly share code, notes, and snippets.

@Underdoge
Created March 6, 2017 05:14
Show Gist options
  • Save Underdoge/48a1022491ff48495ecf263ddeff240d to your computer and use it in GitHub Desktop.
Save Underdoge/48a1022491ff48495ecf263ddeff240d to your computer and use it in GitHub Desktop.
chessBoardCellColor
function chessBoardCellColor(cell1, cell2) {
if((cell1.charCodeAt(0)-64)%2==0&&(cell2.charCodeAt(0)-64)%2==0)
if((cell1.charCodeAt(1)%2!=0&&cell2.charCodeAt(1)%2!=0)||(cell1.charCodeAt(1)%2==0&&cell2.charCodeAt(1)%2==0))
return true;
else
return false;
else
if((cell1.charCodeAt(0)-64)%2!=0&&(cell2.charCodeAt(0)-64)%2!=0)
if((cell1.charCodeAt(1)%2==0&&cell2.charCodeAt(1)%2==0)||(cell1.charCodeAt(1)%2!=0&&cell2.charCodeAt(1)%2!=0))
return true;
else
return false;
else
if((cell1.charCodeAt(0)-64)%2!=0&&(cell2.charCodeAt(0)-64)%2==0)
if((cell1.charCodeAt(1)%2!=0&&cell2.charCodeAt(1)%2==0)||(cell1.charCodeAt(1)%2!=0&&cell2.charCodeAt(1)%2==0))
return true;
else
return false;
}
@abhilash007
Copy link

abhilash007 commented Jun 12, 2017

function chessBoardCellColor(cell1, cell2) {
    var sum_1 = cell1.charCodeAt(0) - 64+parseInt(cell1.charAt(1));
    var sum_2 = cell2.charCodeAt(0) - 64+parseInt(cell2.charAt(1));
    return (sum_1 % 2 === 0 && sum_2 % 2 === 0) || (sum_1 % 2 === 1 && sum_2 % 2 === 1)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment