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

@@ -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;
}
});