@moshmage/

HonorableInternationalLeafwing

ES6

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function createSquare(height) {
    const rows = height || 3; /** use the provided argument or default to 3 */
    const columns = height || 3;
    const field = [];
    for (let x = 0; x < rows; x++) {
        let row = [];
        for (let y = 0; y < columns; y++) {
            /** we set the row/column information inside the slot so we can return an array of slots on win conditions
             * that way we won't to make any special changes to the slot object in the future. */
            let slot = {occupied: false, symbol: '', row: x, column: y};
            row.push(slot);
        }
        field.push(row);
    }
    return field;
}

console.log(createSquare(3))
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie