derek thing

by path411

HTML

<textarea id="gamesinput"></textarea>
<button id="calculate">Calcuate</button>
<div id="output"></div>

JavaScript

(function() {
    
    function Main() {
        BindEvents();
    }
    
    function BindEvents() {
        var $gamesinput = document.getElementById('gamesinput');
        
        document.getElementById('calculate').addEventListener('click', function() {
            var games = ReadGamesFromInput($gamesinput.value);
            Output(games);
        });
    }
    
    function ReadGamesFromInput(input) {
        var rows = input.split('\n');
        var games = [];
        for(var i=1, iL = rows.length; i<iL; i++) {
            var row = rows[i];
            var cols = row.split('\t');
            var game = {
                'Game': cols[0],
                'Region': cols[1],
                'Winner': cols[2],
                'Loser': cols[3],
                'Winners': [
                    cols[4], cols[5], cols[6], cols[7], cols[8]
                ],
                'Losers': [
                    cols[9], cols[10], cols[11], cols[12], cols[13]    
                ]         
            };
            games.push(game);
        }
        
        return games;
    }
    
    
    function Output() {
        document.getElementById('output').innerHTML = JSON.stringify(games);
    }



    Main();
})();