Guest User

Untitled

a guest
Nov 30th, 2012
22
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function splitBill( guests, amount ) {
  2.         var arrOwed = []; var i = 0; var splitamt = 0; var decval = 0; var randguest = 0;
  3.         if ( !isDefined("arguments.guests") || !isNumeric(arguments.amount) || arguments.guests <= 0 )
  4.             return ["The value you provide for guests must be a positive number greater than 0."];
  5.         if ( !isDefined("arguments.amount") || !isNumeric(arguments.amount) || arguments.amount <= 0 )
  6.             return ["The value you provide for amount must be a positive number greater than 0."];
  7.  
  8.         splitamt = arguments.amount / arguments.guests;
  9.         decval = LSParseNumber( listFirst( splitamt, ".") & "." & left( listLast( splitamt, "." ), 2 ) );
  10.         for ( i = 1; i <= arguments.guests; i++ ) {
  11.             if ( listLen( splitamt, ".") == 1 ) {
  12.                 arrayAppend( arrOwed, splitamt );
  13.             } else {
  14.                 arrayAppend( arrOwed, listFirst( splitamt, "." ) & "." & left( listLast( splitamt, "." ), 2 ) );
  15.             }
  16.         }
  17.  
  18.         if ( len( toString( reverse( fix( reverse( splitamt ) ) ) ) ) > 2 ) {
  19.             randguest = randRange( 1, arguments.guests, "SHA1PRNG");
  20.             arrOwed[ randguest ] = decimalFormat( decval + .01 );
  21.         }
  22.         ;
  23.         return arrOwed;
  24.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×