Most of the solutions that people posted are lost to the sands of time (Slack history)
// slice from pre-generated string
function make_board4(width, height) {
const chars = ' #'.repeat(width / 2 + 1);
const odd_row = chars.slice(0, width) + '\n';
const even_row = chars.slice(1, width + 1) + '\n';
let rows = [];
for (let i = 0; i < height; i += 2)
rows.push(odd_row, even_row);
return rows.slice(0, height).join('');
}
- Large family of variations https://github.com/yamad/js/blob/master/chessboard.js
https://repl.it/@JamesPascual/ltccode-challenges-01chessboard
const drawRow = (pattern, maxLength, { lineEnding = '\n' } = {}) => pattern
.repeat( Math.ceil(maxLength / pattern.length) )
.slice(0, maxLength) + lineEnding;
const drawBoard = (width, height, { oddPattern = '# ', evenPattern = ' #', lineEnding = '\n' } = {}) => {
let board = '';
for (let y = 0; y < height; y++) {
board += (y % 2) ? drawRow(oddPattern, width, { lineEnding }) : drawRow(evenPattern, width, { lineEnding });
}
return board;
};