Templates that wrap around with modulo break when the left side is negative. Our carousel works out the previous slide with {{ index | minus: 1 | modulo: count }} and gets -1 on the first slide instead of the index of th…
Templates that wrap around with modulo break when the left side is negative. Our carousel works out the previous slide with {{ index | minus: 1 | modulo: count }} and gets -1 on the first slide instead of the index of the last one. Liquid defines modulo the way Ruby defines %: the result takes the sign of the divisor.
{{ -7 | modulo: 3 }}.{{ 7 | modulo: -3 }}.{{ index | minus: 1 | modulo: count }} with index set to 0 and count set to 5.2-24-11-1{{ 7 | modulo: 3 }} is 1 and {{ -7 | modulo: -3 }} is -1.{{ -4.5 | modulo: 3 }} should be 1.5.0.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
modulo-negative-numbers
Changes under src/ are evaluated.