<commit_before>const boards = {
    win: {
        one: [
            ['O']
        ],
        two: [
            ['O', 'X'],
            ['X', 'X']
        ],
        three: [
            ['O', 'X', 'X'],
            ['O', 'O', 'O'],
            ['X', 'O', 'X']
        ],
        four: [
            ['O', 'X', 'X', 'O'],
            ['X', 'O', 'X', 'O'],
            ['X', 'O', 'X', 'X'],
            ['O', 'X', 'X', 'O'],
        ]
    }
};

/**
 * Transpose an array.
 *
 * This is used to assist in evaluation of win conditions: Rather than change the
 * test to fit board state, it's easier to fit the board to a single win
 * condition (by turning the board sideways).
 *
 *  1. If array is empty or falsy, return an array.
 *  2. If array[0] is not an array itself, return the parent reversed.
 *
 * @param {array} array - Multidimensional array of board cells.
 * @return {array} array - Original array transposed.
 */

function transpose(array) {
    if (!array || !array.length) {
        return [];
    }

    if (!Array.isArray(array[0])) {
        return array.slice().reverse();
    }

    return array[0].map((_, index) => array.map(row => row[index]));
}

/**
 * Return the diagonal elements of a multidimensional array.
 *
 * @param {array} array - Multidimensional array of board cells.
 * @param {array} array - Multidimensional array of diagonal elements.
 */

function diagonals(array) {
    const reversed = array.slice().reverse();

    return [
        array.map((element, index) => array[index][index]),
        array.map((element, index) => reversed[index][index])
    ];
}

/**
 * Test whether all cells of the supplied row contain the given character.
 *
 * @param {array} row - Row to test.
 * @param {string} character - Character to test.
 * @param {bool} - Row cells equal character, true/false.
 */<commit_msg>Added method to generate Tic-tac-toe board of arbitrary size.<commit_after>const boards = {
    win: {
        one: [
            ['O']
        ],
        two: [
            ['O', 'X'],
            ['X', 'X']
        ],
        three: [
            ['O', 'X', 'X'],
            ['O', 'O', 'O'],
            ['X', 'O', 'X']
        ],
        four: [
            ['O', 'X', 'X', 'O'],
            ['X', 'O', 'X', 'O'],
            ['X', 'O', 'X', 'X'],
            ['O', 'X', 'X', 'O'],
        ]
    }
};

/**
 * Generate a square multidimensional array of arbitrary size.
 *
 * @param {number} [size=3] - Size of grid (x and y).
 * @param {*=} value - Value to prepopulate into fields. Defaults to array keys.
 * @return {array} array - Square multidimensional array.
 */

function grid(size, value) {
    let array = [...Array(size || 3).keys()];

    if (value !== undefined) {
        array = array.map(() => value);
    }

    return array.map(() => array);
}

/**
 * Transpose an array.
 *
 * This is used to assist in evaluation of win conditions: Rather than change the
 * test to fit board state, it's easier to fit the board to a single win
 * condition (by turning the board sideways).
 *
 *  1. If array is empty or falsy, return an array.
 *  2. If array[0] is not an array itself, return the parent reversed.
 *
 * @param {array} array - Multidimensional array of board cells.
 * @return {array} array - Original array transposed.
 */

function transpose(array) {
    if (!array || !array.length) {
        return [];
    }

    if (!Array.isArray(array[0])) {
        return array.slice().reverse();
    }

    return array[0].map((_, index) => array.map(row => row[index]));
}

/**
 * Return the diagonal elements of a square multidimensional array.
 *
 * @param {array} array - Multidimensional array of board cells.
 * @param {array} array - Multidimensional array of diagonal elements.
 */

function diagonals(array) {
    const reversed = array.slice().reverse();

    return [
        array.map((element, index) => array[index][index]),
        array.map((element, index) => reversed[index][index])
    ];
}

/**
 * Test whether all cells of the supplied row contain the given character.
 *
 * @param {array} row - Row to test.
 * @param {string} character - Character to test.
 * @param {bool} - Row cells equal character, true/false.
 */
{'fraction_non_alphanumeric': 0.16741973840665875, 'fraction_numerical': 0.002853745541022592, 'mean_word_length': 2.2353846153846155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1927921', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1270, 'n_words': 445}