Num Place 2

<head>
<script type="module">
import * as np from '../num-place-2/2'
var n = new np.Game('4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......');
n.createBoard( document.querySelector('#np') );
console.log(n.cells);
</script>
</head>
<body>
<div id="np"></div>
</body>
export class Game {
    constructor(input) {
        var game = new Array(9).fill(0).map(function(){
            return new Array(9).fill(0).map(function(){
                return new Array(9).fill(0).map(function(_,i){
                    return i+1;
                })
            })
        });
        var stat = input.split('').filter(function(v){return v.match(/\S/)});
        var row = 0, col = 0;
        for(var s of stat) {
 
            if(s.match(/\d/)) {
                game[col][row] = [Number(s)];
            }
            if(row == 8) {
                row = 0;
                col++;
            }else{
                row++;
            }
        }
        this.game = game;
    }
 
    createBoard(wrap) {
        // <table><tbody><tr><td class="x0 y0 u0"></td><td cl
        var cells = new Array(9).fill(0).map(function(){
            return new Array(9).fill(0).map(function(){
                return new Array(9).fill(0);
            })
        });
        var tbl = document.createElement('table');
        var bdy = document.createElement('tbody');
        wrap.appendChild(tbl);
        tbl.appendChild(bdy);
 
        var row = 0, col = 0, tr = document.createElement('tr');
        for(var s of stat) {
            var td = document.createElement('td);
            tr.appendChild(td);
            cells[col][row] = td;
            if(row == 8) {
                row = 0;
                col++;
                bdy.appendChild(tr);
                tr = document.createElement('tr');
            }else{
                row++;
            }
        }
        this.cells = cells;
    }
    combine() {
 
    }
}
table {border: 2px solid #b01;margin: 0 32px 32px 0;}td {width: 32px;font-family: monospace; height: 32px;text-align: center;font-size: 24px;padding: 0;background: #f0fff0;font-weight: bold;}td.u0, td.u2, td.u4, td.u6, td.u8 {background: #fff0f0;}td:before {content: attr(data-num)"";word-break: break-all;}
 
td[data-no] {
    font-size: 6px;
}
td:not([data-def]):not([data-no]) {
    color: red;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License