Observed behaviour:
- Selecting "Low to High" shows products in descending order (highest price first)
- Sorting behaviour is opposite of expected
- UI label does not match actual sorting logic
Steps to reproduce:
- Go to Shop House
- Select "Low to High"
- Observe products are sorted from high to low
Expected behaviour:
- "Low to High" should sort products in ascending order (lowest price first)
Actual behaviour:
- Products are sorted in descending order instead
Root cause:
Sorting comparator logic is reversed:
result.sort((a, b) => (sortDirection === 'asc' ? b.price - a.price : a.price - b.price))
Fix:
Swap the comparator logic:
result.sort((a, b) => (sortDirection === 'asc' ? a.price - b.price : b.price - a.price))
Observed behaviour:
Steps to reproduce:
Expected behaviour:
Actual behaviour:
Root cause:
Sorting comparator logic is reversed:
result.sort((a, b) => (sortDirection === 'asc' ? b.price - a.price : a.price - b.price))
Fix:
Swap the comparator logic:
result.sort((a, b) => (sortDirection === 'asc' ? a.price - b.price : b.price - a.price))