Constellations/js/Grid/Util.js

25 lines
468 B
JavaScript
Raw Permalink Normal View History

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;});
}