Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function agregate(input){
  2.     var num=parseInt(input[0]);
  3.     var primeArr=[];
  4.     for(var i=1; i<num+1; i++){
  5.         primeArr[i-1]=[];
  6.         primeArr[i-1]=input[i].split(' ');
  7.     }
  8.     var workArr=[];
  9.     for(var i=0; i<primeArr.length; i++){
  10.         if(workArr.indexOf(primeArr[i][1])==-1){
  11.             workArr[i]=primeArr[i][1];
  12.         }
  13.     }
  14.     var otherArr=[];
  15.     for(var i=0; i<workArr.length; i++){
  16.         otherArr[i]=[];
  17.         for(var j=0; j<primeArr.length; j++){
  18.             if(workArr[i]==primeArr[j][1]){
  19.                 otherArr[i][0]=primeArr[j][1];
  20.                 if(otherArr[i][1]==undefined){
  21.                     otherArr[i][1] = primeArr[j][0];
  22.                 }
  23.                 else{
  24.                     if(otherArr[i][1].indexOf(primeArr[j][0])==-1) {
  25.                         otherArr[i][1]+=', ' + primeArr[j][0];
  26.                     }
  27.                 }
  28.                 if(otherArr[i][2]==undefined){
  29.                     otherArr[i][2] = parseInt(primeArr[j][2]);
  30.                 }
  31.                 else {
  32.                     otherArr[i][2]+=parseInt(primeArr[j][2]);
  33.                 }
  34.             }
  35.         }
  36.     }
  37.     otherArr.sort();
  38.     var sortIps=[];
  39.     for(var i=0; i<otherArr.length; i++){
  40.         sortIps[i]=otherArr[i][1].split(', ');
  41.         sortIps[i].sort();
  42.         console.log(otherArr[i][0] + ': ' + otherArr[i][2] + ' [' + sortIps[i].join(', ') + ']');
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement