From 57adfa505102672089a385751c518999114bfc83 Mon Sep 17 00:00:00 2001 From: reutmaduel114-collab Date: Tue, 23 Dec 2025 15:07:30 +0200 Subject: [PATCH] Add type annotations and return types to product-related functions --- store.ts | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/store.ts b/store.ts index 1745d61..35dfcda 100644 --- a/store.ts +++ b/store.ts @@ -79,43 +79,47 @@ const cart = [1, 3, 5]; // ------------------------------------ function getAvailableProducts( - store /* : add type here */ -) /* : add return types */ { - return []; + store : Store /* : add type here */ +) : Product[] /* : add return types */ { + return store.products.filter((product => product.inStock)); } function getProductsInPriceRange( - store /* : add type here */, - minPrice /* : add type here */, - maxPrice /* : add type here */ -) /* : add return types */ { - return []; + store : Store /* : add type here */, + minPrice: number /* : add type here */, + maxPrice: number /* : add type here */ +):Product[] /* : add return types */ { + return store.products.filter((product => + product.price >= minPrice && product.price <= maxPrice)); } function getProductsByTag( - store /* : add type here */, - tag /* : add type here */ -) /* : add return types */ { - return []; + store: Store /* : add type here */, + tag: string /* : add type here */ +): Product[] /* : add return types */ { + return store.products.filter((product => + product.tags.includes(tag))); } function getAvailableProductsByTag( - store /* : add type here */, - tag /* : add type here */ -) /* : add return types */ { - return []; + store: Store /* : add type here */, + tag: string /* : add type here */ +) : Product[] /* : add return types */ { + return store.products.filter((product => + product.inStock && product.tags.includes(tag)) + ); } function getCartProducts( - store /* : add type here */, - cart /* : add type here */ -) /* : add return types */ { + store: Store /* : add type here */, + cart: number[] /* : add type here */ +) :Product[]/* : add return types */ { return []; } function getCartTotalInStock( - store /* : add type here */, - cart /* : add type here */ -) /* : add return types */ { + store: Store /* : add type here */, + cart: number[] /* : add type here */ +) : number /* : add return types */ { return 0; }