Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Xs and Os Referee by flairplaya
"use strict";
function xoReferee(data) {
var c = data[1][1];
function check(str) {
return str == "XXX" || str == "OOO" ? 1 : 0;
}
for(var i = 0; i < data.length; i++) {
if(check(data[i])) return data[i][0];
if(check(data[0][i]+data[1][i]+data[2][i])) return data[0][i];
}
return check(data[0][0]+c+data[2][2]) || check(data[0][2]+c+data[2][0]) ? c : "D";
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(xoReferee([
"X.O",
"XX.",
"XOO"]), "X", "Xs wins");
assert.equal(xoReferee([
"OO.",
"XOX",
"XOX"]), "O", "Os wins");
assert.equal(xoReferee([
"OOX",
"XXO",
"OXX"]), "D", "Draw");
assert.equal(xoReferee([
"O.X",
"XX.",
"XOO"]), "X", "Xs wins again");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Sept. 17, 2018