simple underscore.js projects, walk through, & tutorial


Lottery DataBase Analysis - 07 (_.isObject & passing an object)


From Here on Out, I will no longer be pasting this table into the web page or creating the JSON object dynamically.

THIS SPUR explains how the table got transformed into JSON and I will simply utilize the transformed JSON data from here on out.  Doing this will save the need to load the TableToJSON library.  And until it is needed for graphical output (I expect to try my hand at FLOT with requires JQuery), the JQuery library will no longer be required either.  (Of course, one of the reasons for doing this is an error I was gettign from using multiple libraries at once.)


California Lucky for Life (832)
Prizes Odds 1 in Total # of Winners Prizes Claimed Prizes Available
$3,250,000 2,400,000 17 11 6
$5,000 1,200,000 34 22 12
$1,000 400,000 102 65 37
$500 12,000 3,400 2,239 1,161
$100 645 63,240 41,624 21,616
$40 350 116,620 76,812 39,808
$20 53 765,000 498,167 266,833
$15 40 1,020,000 668,467 351,533
$10 20 2,040,000 1,325,571 714,429
$5 11 3,570,000 2,287,131 1,282,869
Ticket 10 4,080,000 2,524,475 1,555,525

The above reduces to:

[{"Prizes":"$3,250,000","Odds 1 in":"2,400,000","Total # of Winners":"17","Prizes Claimed":"11","Prizes Available":"6"},{"Prizes":"$5,000","Odds 1 in":"1,200,000","Total # of Winners":"34","Prizes Claimed":"22","Prizes Available":"12"},{"Prizes":"$1,000","Odds 1 in":"400,000","Total # of Winners":"102","Prizes Claimed":"65","Prizes Available":"37"},{"Prizes":"$500","Odds 1 in":"12,000","Total # of Winners":"3,400","Prizes Claimed":"2,239","Prizes Available":"1,161"},{"Prizes":"$100","Odds 1 in":"645","Total # of Winners":"63,240","Prizes Claimed":"41,624","Prizes Available":"21,616"},{"Prizes":"$40","Odds 1 in":"350","Total # of Winners":"116,620","Prizes Claimed":"76,812","Prizes Available":"39,808"},{"Prizes":"$20","Odds 1 in":"53","Total # of Winners":"765,000","Prizes Claimed":"498,167","Prizes Available":"266,833"},{"Prizes":"$15","Odds 1 in":"40","Total # of Winners":"1,020,000","Prizes Claimed":"668,467","Prizes Available":"351,533"},{"Prizes":"$10","Odds 1 in":"20","Total # of Winners":"2,040,000","Prizes Claimed":"1,325,571","Prizes Available":"714,429"},{"Prizes":"$5","Odds 1 in":"11","Total # of Winners":"3,570,000","Prizes Claimed":"2,287,131","Prizes Available":"1,282,869"},{"Prizes":"Ticket","Odds 1 in":"10","Total # of Winners":"4,080,000","Prizes Claimed":"2,524,475","Prizes Available":"1,555,525"}]

Which I have saved as a JSON Object.  (The above is nothing more than HTML text and is not linked to any JavaScript.) 



    //Array to pass to Next Function (to determine Expected Return Per Prize Level)
    var tempArray1 = _.zip(prizeAmounts, numWin);
    document.getElementById('outputOne').innerHTML = _.map(tempArray1, function(n){return ' ' + n;});

outputOne =
1 Nada Yet


   
    // Error is An Object
    var tempArray2 = _.map(tempArray1, function(a){return _.isObject(a);});
    document.getElementById('outputTwo').innerHTML = _.map(tempArray2, function(n){return ' ' + n;});

outputTwo =
2 Nada Yet



    var tempArray3 = _.map(tempArray1, function(a,b){return a * b;});
    document.getElementById('outputTwo').innerHTML = _.map(tempArray3, function(n){return ' ' + n;});

tputThree =
3 Nada Yet



    var tempArray4 = _.map(tempArray1, function(a){
        return a[0] * a[1];
    });
    document.getElementById('outputTwo').innerHTML = _.map(tempArray4, function(n){return ' ' + n;});

outputFour =
4 Nada Yet


Using the original JSON lotteryData, we can pull data directly (so don't ask me why I was plucking and zipping before.


    var tempArray5 = _.map(lotteryData, function(a){
            return a.Prizes;
            //Total # of Winners

    });
    document.getElementById('outputTwo').innerHTML = _.map(tempArray5, function(n){return ' ' + n;});

outputFive =
5 Nada Yet


    This last indates that:
  1. There are easier ways to pull data from a JSON object.
  2. My life will be easier in the long run if I preformat the JSON object (remove strings, rename keys, maybe more).

    So, time to reformat the Spur again.


Permanent Display Stats
error


_.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.