generator-begcode
Version:
Spring Boot + Angular/React/Vue in one handy generator
20 lines (19 loc) • 427 B
JavaScript
export class PriorityContainer {
maxSize;
compareFn;
items = [];
constructor(maxSize, compareFn) {
this.maxSize = maxSize;
this.compareFn = compareFn;
}
addItem(item) {
this.items.push(item);
this.items.sort(this.compareFn);
if (this.items.length > this.maxSize) {
this.items.pop();
}
}
getItems() {
return this.items;
}
}