simple underscore.js projects, walk through, & tutorial


Lottery DataBase Analysis - 10 (_.min & _.max)


Not much code.
Learned there was no average function in underscore.
Will likely have to import JStat before long.

Determining an Absolute Number of Tickets Sold (and therefore Number of Tickets Outstanding).

//Computational Code
    var numTicketsBought = _.map(lotteryData, function(a){
        return a.numClaimed * a.oddsThis;
    });
    var numTicketsBoughtMax = _.max(numTicketsBought);
    var numTicketsBoughtMin = _.min(numTicketsBought);
    var numTicketsBoughtAverage = _.reduce(numTicketsBought, function(a,b){return a + b;}, 0)/numTicketsBought.length;

//Output Code
    document.getElementById('outputOne').innerHTML = "Big Prize = $" + lotteryData[0].prizeThis;
    document.getElementById('outputTwo').innerHTML = "Big Prize Return per $1 = $" + lotteryData[0].prizeThis/ticketPrice;
    document.getElementById('outputThree').innerHTML = "Number of Tickets Bought Max = " + numTicketsBoughtMax;
    document.getElementById('outputFour').innerHTML = "Number of Tickets Bought Min = " + numTicketsBoughtMin;;
    document.getElementById('outputFive').innerHTML = 'Number of Tickets Bought Average = ' + numTicketsBoughtAverage;
    document.getElementById('outputSix').innerHTML = 'NumTicketsBought Array = (for proofing)' + _.map(numTicketsBought, function(n){return ' ' + n;});


1 Nada Yet

2 Nada Yet

3 Nada Yet

4 Nada Yet

5 Nada Yet

5 Nada Yet


I also cleaned up all the output by using Math.floor &

function twoDigits(x){
    return (Math.floor(100*x))/100;
}


Permanent Display Stat area (summary of all meaningful stats, to date for this project):
nada yet
nada yet
nada yet
nada yet
nada yet
nada yet

nada yet
nada yet

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.