Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Get all the lines together solution in Clear category for [old] Xs and Os Referee by oduvan
"use strict";
function checkio(data) {
var chars = data.map(function (a) {return a.split('')});
for(var i=0; i<3; i++){
data.push(chars[0][i] + chars[1][i] + chars[2][i]);
}
data.push(chars[0][0] + chars[1][1] + chars[2][2]);
data.push(chars[2][0] + chars[1][1] + chars[0][2]);
if (data.indexOf("XXX") + 1) {
return "X"
}
if (data.indexOf("OOO") + 1) {
return "O"
}
return "D"
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(checkio([
"X.O",
"XX.",
"XOO"]), "X", "Xs wins");
assert.equal(checkio([
"OO.",
"XOX",
"XOX"]), "O", "Os wins");
assert.equal(checkio([
"OOX",
"XXO",
"OXX"]), "D", "Draw");
assert.equal(checkio([
"O.X",
"XX.",
"XOO"]), "X", "Xs wins again");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
June 18, 2016
Comments: