Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function agregate(input){
- var num=parseInt(input[0]);
- var primeArr=[];
- for(var i=1; i<num+1; i++){
- primeArr[i-1]=[];
- primeArr[i-1]=input[i].split(' ');
- }
- var workArr=[];
- for(var i=0; i<primeArr.length; i++){
- if(workArr.indexOf(primeArr[i][1])==-1){
- workArr[i]=primeArr[i][1];
- }
- }
- var otherArr=[];
- for(var i=0; i<workArr.length; i++){
- otherArr[i]=[];
- for(var j=0; j<primeArr.length; j++){
- if(workArr[i]==primeArr[j][1]){
- otherArr[i][0]=primeArr[j][1];
- if(otherArr[i][1]==undefined){
- otherArr[i][1] = primeArr[j][0];
- }
- else{
- if(otherArr[i][1].indexOf(primeArr[j][0])==-1) {
- otherArr[i][1]+=', ' + primeArr[j][0];
- }
- }
- if(otherArr[i][2]==undefined){
- otherArr[i][2] = parseInt(primeArr[j][2]);
- }
- else {
- otherArr[i][2]+=parseInt(primeArr[j][2]);
- }
- }
- }
- }
- otherArr.sort();
- var sortIps=[];
- for(var i=0; i<otherArr.length; i++){
- sortIps[i]=otherArr[i][1].split(', ');
- sortIps[i].sort();
- console.log(otherArr[i][0] + ': ' + otherArr[i][2] + ' [' + sortIps[i].join(', ') + ']');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement