Advertisement
Guest User

Array.prototype.indexesOfGreatestNums

a guest
Aug 21st, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // http://prohardver.hu/tema/javascript_topic/hsz_3701-3701.html
  2.  
  3. Array.prototype.indexesOfGreatestNums = function () {
  4.   var result = new String,
  5.     a = new Array,
  6.     b = new Array;
  7.   c = new Array;
  8.  
  9.   a[0] = 0, b[0] = 0;
  10.  
  11.   for (var i = 0, j = 0; i < this.length; i++) {
  12.     if (this[i] > 0) {
  13.       if (a.indexOf(this[i].toString()) >= 0) {
  14.         if (b[a.indexOf(this[i].toString())] !== undefined) {
  15.           b[a.indexOf(this[i].toString())]++
  16.         } else {
  17.           b[a.indexOf(this[i].toString())] = 1;
  18.         };
  19.       } else {
  20.         a[j] = this[i];
  21.         if (b[j] !== undefined) {
  22.           b[j]++
  23.         } else {
  24.           b[j] = 1
  25.         };
  26.         j++;
  27.       }; //end else
  28.     }; // end if
  29.   }; // end for
  30.  
  31.   //var ok = popup('',a + '\n' + b,false,'','',30);
  32.   var that = this.slice(0);
  33.  
  34.   for (i = 0; i < a.length; i++) {
  35.     for (j = 0; j < b[a.indexOf(Math.max.apply('', a).toString())]; j++) {
  36.       //flash(that.join() +'\n'+ a.join());
  37.       c[j] = that.indexOf(Math.max.apply('', a).toString());
  38.       that[that.indexOf(Math.max.apply('', a).toString())] = 0;
  39.     }; //end for
  40.     result = result + c.join() + '>';
  41.     c = [];
  42.     a[a.indexOf(Math.max.apply('', a).toString())] = 0;
  43.   }; // end for
  44.  
  45.   return (result);
  46. }; // end prototype
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement