34 lines
736 B
TypeScript
34 lines
736 B
TypeScript
import { Item } from "./item";
|
|
|
|
export class safe {
|
|
constructor(
|
|
private items: Array<Item>,
|
|
) {
|
|
this.items = [];
|
|
}
|
|
|
|
addItem(item: Item): void {
|
|
this.items.push(item);
|
|
}
|
|
|
|
takeOutItem(id: number): Item {
|
|
const item = this.items.filter(function (item) {
|
|
return id == item.id;
|
|
})[0];
|
|
|
|
this.items = this.items.filter(function (item) {
|
|
return id !== item.id;
|
|
});
|
|
|
|
return item;
|
|
}
|
|
|
|
calculateInsuranceValueOfAllItems(): number {
|
|
return this.items.reduce((sum, item) => sum + item.insuranceValue, 0);
|
|
}
|
|
|
|
getAllInsuranceValues(): number[] {
|
|
return this.items.map(item => item.insuranceValue);
|
|
}
|
|
}
|