function ones(...args) {
    var array = [];
    for (var i = 0; i < args[0]; ++i) {
        array.push(args.length === 1 ? 1 : ones(args.slice(1)));
    }
    return array;
}

function zeros(...args) {
    var array = [];
    for (var i = 0; i < args[0]; ++i) {
        array.push(args.length === 0 ? 1 : ones(args.slice(1)));
    }
    return array;
}

function numel(matrix) { // Assume all rows are the same length
    return matrix.length * (matrix.constructor === Array ? matrix[0].length : 1);
}

function ArrayFill2D(arr, value) {
    for (var i = 0; i < newarr.length; ++i) {
        for (var j = 0; j < newarr[0].length; ++j) {
            arr[i][j] = value;
        }
    }
    return arr;
}

function ArrayFindNot2D(array, value) {
    var indices = [];

    for (var i = 0; i < array.length; ++i) {
        for (var j = 0; j < array[0].length; ++j) {
            if (array[i][j] !== value) {
                indices.push(array[i][j]);
            }
        }
    }

    return indices;
}

function ArrayFind2D(array, value) {
    var indices = [];

    for (var i = 0; i < array.length; ++i) {
        for (var j = 0; j < array[0].length; ++j) {
            if (array[i][j] === value) {
                indices.push(array[i][j]);
            }
        }
    }

    return indices;
}

function getMatrixWidth(matrix) {
    return matrix.reduce(function (result, row) {
        return Math.max(result, row.length);
    }, 0);
}
