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 nlupton
"use strict";
function xoReferee(data) {
let verticalrows = [];
data.map( (mapcur, index) =>
verticalrows.push( data.reduce( (acc,cur) => acc + cur.charAt(index) , ''))
);
let diagrows = [data[0].charAt(0) + data[1].charAt(1) + data[2].charAt(2),
data[0].charAt(2) + data[1].charAt(1) + data[2].charAt(0)];
data = [...data, ...verticalrows, ...diagrows];
return data.includes("XXX") ? "X" :
data.includes("OOO") ? "O" :
"D";
}
console.log ( xoReferee( ["X.O", "XX.", "XOO"] ) );
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!");
}
May 12, 2017
Comments: