Linear search examines an array sequentially for an item. Extracting this loop into indexOfItem() makes the search reusable while keeping cart-specific knowledge in one lower-level function. section 8.7
Searching a shopping cart
indexOfItem(cart, name) returns the matching array index or null when no item matches. remove_item_by_name() can then delegate removal to that result, while isInCart() converts it into a boolean. section 8.7
Browse the extracted JavaScript implementation, including sequential comparison, index return, and the null result for an exhausted collection. section 8.7




