Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Pawn Brotherhood by SaintDron
"use strict";
function safePawns(data) {
const chars = 'abcdefgh';
let n, c, result = 0;
for (let v of data) {
n = v[1] - 1;
c = [ chars[chars.indexOf(v[0]) - 1], chars[chars.indexOf(v[0]) + 1] ];
if (data.includes(c[0] + n) || data.includes(c[1] + n))
result++;
}
return result;
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(safePawns(["b4", "d4", "f4", "c3", "e3", "g5", "d2"]), 6, "First");
assert.equal(safePawns(["b4", "c4", "d4", "e4", "f4", "g4", "e5"]), 1, "Second");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
March 4, 2018
Comments: