simple underscore.js projects, walk through, & tutorial


Lottery DataBase Analysis - 08 (_.chain)




var ticketPrice = 0;

// reformat lottery data to Intergers
// And compute ticket price
lotteryData = _.chain(lotteryData)
    .map(function(a){
        a.prizeThis = a.prizeThis.replace(/\$/g, "");
            if (a.prizeThis != 'Ticket') {
                a.prizeThis = parseInt(a.prizeThis.replace(/,/g,""),10);
                ticketPrice = a.prizeThis;
            } else if (a.prizeThis === 'Ticket'){
                a.prizeThis = ticketPrice;
            }
        a.oddsThis = parseInt(a.oddsThis.replace(/,/g,""),10);
        a.numWinners = parseInt(a.numWinners.replace(/,/g,""),10);
        a.numClaimed = parseInt(a.numClaimed.replace(/,/g,""),10);
        a.numAvailable = parseInt(a.numAvailable.replace(/,/g,""),10);
        return a;
        })
    .value();


1 Nada Yet

(from above code)
2 Nada Yet


    var numTickets = lotteryData[0].oddsThis * lotteryData[0].numWinners;

3 Nada Yet


NOTE: this is reflected in JSON object output as well

// Add two new derived properties to lotteryData
lotteryData = _.map(lotteryData,
    function(a){
        a.returnPerThis = a.prizeThis * a.numWinners / numTickets;
        a.returnPerDollar = a.returnPerThis / ticketPrice;
        return a;
    }
);


var returnPerTicket = _.reduce(lotteryData, function(a,b){return a + b.returnPerThis;}, 0);

4 Nada Yet


var returnPerTicketDollar = returnPerTicket / ticketPrice;   

5 Nada Yet





Permanent Display Stat area
nada yet
nada yet
nada yet
nada yet


_.moreUnderscoreProjects

© Copyright 2013 Brett Paufler


Please Note: I am an idiot.  No seriously.  The odds of my gambling odds calculations being correct are likely on par with my odds of ever winning.  You have been warned.