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; }