Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re🏭ed solution in Clear category for [old] Chess Knight by vincent.tscherter
Array.prototype.unique = function () {
return this.filter((c,i,a) => a.indexOf(c) === i);
}
var chessKnight = (start, moves) => {
let createMoves = pos => [-18, 22, 41, 39, 18, -22, -41, -39]
.map(p => (parseInt(pos, 20) + p).toString(20))
.filter(p => p.match(/[a-h][1-8]/)),
out = createMoves(start);
while(--moves) out.forEach(pos =>
out = [...out, ...createMoves(pos)].unique());
return out.sort();
}
Oct. 4, 2018
Comments: