Shopify interview question

Adding some complexity to the initial problem after completing the code