Source: site.view [edit]
Function name: test2
Arguments:
Description:
Page type: webl
Render function:  
Module: sportstreak

Page source:

var seed = 0;
var stat = "Career Blocks Per Game";

  // The higher the better usually, except for ESPN ranking.
  var getStat = fun(player, stat, reverseESPN)
      var s = (ToReal(player[stat]) ? 0);
      if reverseESPN and (stat == "ESPN Ranking") then
         s = 76 - s
      end;
      return s
  end;

  var MAXRND = 503;

  // Returns a random number mod max
  // Seed number makes random number static or not
  var getRndWithDateSeed = fun(date, max, seed)
     var rnd = WubCall("sportstreak.getRandom", [date, MAXRND]);
     seed = seed + 1;
     if (seed > MAXRND) then
        seed = 0
     end;
     return rnd[seed] mod max
  end;

var players = WubCall("getPlayerData", []);

  // Sort the players based on Stat
var sortedPlayers = Sort(players, fun(p1, p2)
            var s1 = getStat(p1, stat, true);
            var s2 = getStat(p2, stat, true);
            if s1 > s2 then return 1
            elsif s1 == s2 then return 0
            else return -1
            end
         end);


var s = "";
var i = 0;
while i < Size(sortedPlayers) do
   s = s + sortedPlayers[i]["Player Name"] + ": " + ToString(getStat(sortedPlayers[i], stat, false)) + "\n";
   i = i + 1
end;

s;