typescript_safe/safe.ts

34 lines
736 B
TypeScript
Raw Normal View History

2024-11-06 09:57:58 +00:00
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);
}
}