24 lines
468 B
JavaScript
24 lines
468 B
JavaScript
return {
|
|
generate: generate,
|
|
iter: iter,
|
|
square: square
|
|
};
|
|
|
|
function generate(width, height, f) {
|
|
var result = [];
|
|
for(var row = 0; row < height; row++) {
|
|
result[row] = [];;
|
|
for(var column = 0; column < width; column++) {
|
|
result[row].push(f(row, column));
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function iter(grid, f) {
|
|
generate(grid.length > 0 ? grid[0].length : null, grid.length, f);
|
|
}
|
|
|
|
function square(size) {
|
|
return generate(size, size, function() {return;});
|
|
}
|