Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
RegEx solution solution in Clear category for [old] Xs and Os Referee by ZweiStein
"use strict";
function xoReferee(data) {
data = data.join(" ");
if (/XXX|X.. .X. ..X|..X .X. X..|X.. X.. X..|.X. .X. .X.|..X ..X ..X/g.test(data)) return "X";
if (/OOO|O.. .O. ..O|..O .O. O..|O.. O.. O..|.O. .O. .O.|..O ..O ..O/g.test(data)) return "O";
return "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!");
}
Aug. 21, 2017
Comments: