Product lists sorted by a property come out in the wrong order when some items do not have that property: those items stay where they were and break up the order of the items around them. Separately, sort_natural cannot…
Product lists sorted by a property come out in the wrong order when some items do not have that property: those items stay where they were and break up the order of the items around them. Separately, sort_natural cannot sort by a nested property such as author.name, although sort can. It returns the list unsorted.
{{ arr | sort: "price" | map: "name" | join: "," }} with arr set to tea (price 4), gift card (no price), mug (price 9) and pen (price 2), in that order.{% assign sorted = arr | sort %}{% for item in sorted %}[{{ item }}]{% endfor %} with arr set to [3, null, 1, 2].{{ posts | sort_natural: "author.name" | map: "title" | join: "," }} with posts B (author name zed), A (Amy) and C (bob), in that order.pen,tea,mug,gift card[1][2][3][]A,C,Btea,gift card,pen,mug[][1][2][3]B,A,Csort_natural already does this for a top-level property.sort_natural stays case-insensitive, also for nested properties.Adapted from harttle/liquidjs (MIT).
Visible test command
TZ=UTC npx --no-install jest --ci --coverage=falseThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
sort-misplaces-items-missing-the-property
Changes under src/ are evaluated.