Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

getTotalCost(): number { let totalCost = 0; for (let item of this._items) { totalCost +=…

  1. User

    getTotalCost(): number { let totalCost = 0; for (let item of this._items) { totalCost += item.price; } return totalCost; }

    Замеени данный код, используя Метод reduce() typescript

  2. Assistant

    getTotalCost(): number { return this._items.reduce((acc, item) => acc + item.price, 0); }