index.js
// tblArray is the 2d JS array
tblArray is the 2d JS array
tblArray is the 2d JS array
function recalculate(){
    for (var i = 0; i < TBLROWS; i++){
        for (var j = 0; j < TBLCOLUMNS; j++){
            if (tblArray[i][j].indexOf("=SUM") !== -1){
                calculateCell(i, j);
            } else if (isCellRef(tblArray[i][j])) {
                var focusedCell = document.getElementById('selectedCell').value;
                var cellLitteralID = tblArray[i][j].substr(1);
                var litteralContent = document.getElementById(cellLitteralID).textContent;
                document.getElementById(focusedCell).innerText = litteralContent;
            } else if (tblArray[i][j]) {
                var letter = String.fromCharCode("A".charCodeAt(0)+j);
                var idNeeded = letter+(i+1);
                document.getElementById(idNeeded).innerText = tblArray[i][j];
            } else {
                var letter = String.fromCharCode("A".charCodeAt(0)+j);
                var idNeeded = letter+(i+1);
                document.getElementById(idNeeded).innerText = "";
            }
        };
    };
}
function recalculate ( ) { for ( var i = 0 ; i < TBLROWS ; i ++ ) { for ( var j = 0 ; j < TBLCOLUMNS ; j ++ ) { if ( tblArray [ i ] [ j ] . indexOf ( "=SUM" ) !== - 1 ) { calculateCell ( i , j ) ; } else if ( isCellRef ( tblArray [ i ] [ j ] ) ) { var focusedCell = document . getElementById ( 'selectedCell' ) . value ; var cellLitteralID = tblArray [ i ] [ j ] . substr ( 1 ) ; var litteralContent = document . getElementById ( cellLitteralID ) . textContent ; document . getElementById ( focusedCell ) . innerText = litteralContent ; } else if ( tblArray [ i ] [ j ] ) { var letter = String . fromCharCode ( "A" . charCodeAt ( 0 ) + j ) ; var idNeeded = letter + ( i + 1 ) ; document . getElementById ( idNeeded ) . innerText = tblArray [ i ] [ j ] ; } else { var letter = String . fromCharCode ( "A" . charCodeAt ( 0 ) + j ) ; var idNeeded = letter + ( i + 1 ) ; document . getElementById ( idNeeded ) . innerText = "" ; } } ; } ; }
tblArray is the 2d JS array
tblArray is the 2d JS array
// check to see if table element is a formula // apply the formula for cell at row/column i/j // if it is a litteral to cell Reference  // litteral id without "=" // literal reference // assign value from cell to cell with literal // if there are somthing // in case formula was left blank or false