grid = (colCount, rowCount, cellLength) => {
const width = colCount * cellLength;
const height = rowCount * cellLength;
const magicOffset = 0.5;
const className = (tick, sideLength) => {
if ((tick === magicOffset) || (tick === (sideLength + magicOffset))) {
return "outer-grid-line";
} else {
return "inner-grid-line";
}
}
const verticalLine = (x) =>
`<line class="${className(x, width)}" x1="${x}" y1="${magicOffset}" x2="${x}" y2="${height + magicOffset}" />`;
const horizontalLine = (y) =>
`<line class="${className(y, height)}" x1="${magicOffset}" y1="${y}" x2="${width + magicOffset}" y2="${y}" />`;
let grid = "";
for (let row = 0; row <= rowCount; row++) {
const tick = (row * cellLength) + magicOffset;
grid += horizontalLine(tick);
}
for (let col = 0; col <= colCount; col++) {
const tick = (col * cellLength) + magicOffset;
grid += verticalLine(tick);
}
return grid;
}