Fixed some sort() functions, added a groupby function

This commit is contained in:
Deon George 2022-04-24 22:36:47 +10:00
parent 3c6d7d057e
commit c1980c359e
3 changed files with 16 additions and 8 deletions

View File

@ -5,7 +5,7 @@
load('load/string.js');
load('ansitex/load/msgbases.js');
ma = new MsgAreas()
const ma = new MsgAreas()
for (var i=0;i<ma.areas.length;i++) {
writeln('Area: '+ma.areas[i].full_name);
writeln('Total Messages: '+ma.areas[i].list.length);
@ -14,7 +14,7 @@ for (var i=0;i<ma.areas.length;i++) {
writeln(' '+ma.areas[i].list_tagged.map(function(x) { return x.tags; }).sort().join('|'));
writeln('Untagged Messages: '+ma.areas[i].list_untagged.length);
writeln(' '+ma.areas[i].list_untagged.map(function(x) { return x.number; }).sort().join('|'));
writeln(' '+ma.areas[i].list_untagged.map(function(x) { return x.number; }).sort(function(a,b) { return a-b; }).join('|'));
ma.areas[i].tag_msgs();
}

View File

@ -46,6 +46,18 @@ if (!String.prototype.repeat) {
};
}
// Group By
if (!Array.prototype.groupby) {
Array.prototype.groupby = function(prop) {
return this.reduce(function(groups, item) {
const val = item[prop]
groups[val] = groups[val] || []
groups[val].push(item)
return groups
}, {})
};
}
/**
* Convert ANSI into BIN for loading into a Frame
*
@ -70,10 +82,6 @@ function ans2bin(ansi,frame) {
}
}
function compare(a,b) {
return (a.prefix < b.prefix) ? 1 : ((b.prefix < a.prefix) ? -1 : 0);
}
/**
* Find a message base by code
*
@ -162,7 +170,7 @@ function getPageOwners() {
f.close();
// Sort the pageowners ascending
pageowners.sort(compare);
pageowners.sort(function(a,b) { return (a.prefix < b.prefix) ? 1 : ((b.prefix < a.prefix) ? -1 : 0); });
//log(LOG_DEBUG,'+ pageOwner: pageowners='+JSON.stringify(pageowners));
}

View File

@ -120,7 +120,7 @@ function MsgArea() {
}
}
return this.untagged_list.sort(function(x) { return x.when_written_time-(x.when_written_zone_offset*60); });
return this.untagged_list;
}
});