lib/matrix.js
function getMatrix(data) {
    var matrix = init(data.version);
    fillFinders(matrix);
    fillAlignAndTiming(matrix);
    fillStub(matrix);

    var penalty = Infinity;
    var bestMask = 0;
    for (var mask = 0; mask < 8; mask++) {
        fillData(matrix, data, mask);
        fillReserved(matrix, data.ec_level, mask);
        var p = calculatePenalty(matrix);
        if (p < penalty) {
            penalty = p;
            bestMask = mask;
        }
    }

    fillData(matrix, data, bestMask);
    fillReserved(matrix, data.ec_level, bestMask);

    return matrix.map(function(row) {
        return row.map(function(cell) {
            return cell & 1;
        });
    });
}
function getMatrix(data) {
    var matrix = init(data.version);
    fillFinders(matrix);
    fillAlignAndTiming(matrix);
    fillStub(matrix);

    var penalty = Infinity;
    var bestMask = 0;
    for (var mask = 0; mask < 8; mask++) {
        fillData(matrix, data, mask);
        fillReserved(matrix, data.ec_level, mask);
        var p = calculatePenalty(matrix);
        if (p < penalty) {
            penalty = p;
            bestMask = mask;
        }
    }

    fillData(matrix, data, bestMask);
    fillReserved(matrix, data.ec_level, bestMask);

    return matrix.map(function(row) {
        return row.map(function(cell) {
            return cell & 1;
        });
    });
}
function getMatrix ( data ) { var matrix = init ( data . version ) ; fillFinders ( matrix ) ; fillAlignAndTiming ( matrix ) ; fillStub ( matrix ) ; var penalty = Infinity ; var bestMask = 0 ; for ( var mask = 0 ; mask < 8 ; mask ++ ) { fillData ( matrix , data , mask ) ; fillReserved ( matrix , data . ec_level , mask ) ; var p = calculatePenalty ( matrix ) ; if ( p < penalty ) { penalty = p ; bestMask = mask ; } } fillData ( matrix , data , bestMask ) ; fillReserved ( matrix , data . ec_level , bestMask ) ; return matrix . map ( function ( row ) { return row . map ( function ( cell ) { return cell & 1 ; } ) ; } ) ; }
{{{1 All-in-one function
{{{ 1 All - in - one function