SHARE
TWEET

biggest table row

a guest Nov 21st, 2014 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tableRow(input){debugger;
  2.     var sum = 0;
  3.     var maxSum = Number.MIN_VALUE;
  4.     var output = '';
  5.    // var tempExp = '';
  6.  
  7.     for (var i = 2; i < input.length - 1; i++) {
  8.         var values = input[i].match(/[-][0-9.]+|[0-9.]+/g);
  9.         if (values == null){
  10.             continue;
  11.         } else{
  12.             for(var j = 0; j < values.length; j++){
  13.                 values[j] = parseFloat(values[j]);
  14.                 sum = sum + values[j];
  15.                // sum = Math.round(sum * 100) / 100
  16.                //var tempExp = ''+ sum + ' = ' +
  17.             }
  18.             if(sum > maxSum){
  19.                 maxSum = sum;
  20.                 output = '' + maxSum + ' = ' + values.join(' + ');
  21.                 sum = 0;
  22.             }
  23.         }
  24.  
  25.     }
  26.     if(maxSum == Number.MIN_VALUE){
  27.         console.log('no data');
  28.     }else{
  29.         console.log(output);
  30.     }
  31.  
  32. }
  33. tableRow(['\<table>',
  34.     '\<tr><th>Town</th><th>Store1</th><th>Store2</th><th>Store3</th></tr>',
  35. '\<tr><td>Varna</td><td>-</td><td>18.02</td><td>36.11</td></tr>',
  36. '\<tr><td>Pleven</td><td>1</td><td>-</td><td>1</td></tr>',
  37. '\<tr><td>Vidin</td><td>12850</td><td>-560</td><td>20833</td></tr>',
  38. '\<tr><td>Rousse</td><td>-</td><td>299.999999</td><td>-</td></tr>',
  39. '\<tr><td>Bourgas</td><td>-</td><td>25000</td><td>-</td></tr>',
  40. '\<tr><td>Plovdiv</td><td>17.2</td><td>-</td><td>6.4</td></tr>',
  41. '\<tr><td>Sofia</td><td>-</td><td>1</td><td>1</td></tr>',
  42. '\</table>'])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top