Wow. That error has been around a while, and I'm surprised nobody noticed and reported it. It's actually a bug in lexpjs, the parser/executor for expressions... it's sorting the array in place rather than sorting a copy that it then returns. That's not consistent with its spec, and I can easily fix that and get it into the next build. That bug causes other expression values to be modified when they should not be (the effect is pretty obvious in the image, for example, the first price is not 0, so the first night_price should not be 0 either).
If you need to work around it, clone your array before sorting it:
sorted_array = sort( clone( price_array ), $2 - $1 )
I also added a little shortcut there for the sorting function. You don't specifically need to return +/-1 or 0, the sort will look at anything positive, negative, or zero, so simple subtraction can take the place of the more complex conditional expression.
The clone()
should not be necessary in future builds.
Here's what it looks like for me now with the lexpjs fix in place (no clone()
needed):
Thank you for including a copy of the source array in text form. That was super-helpful and a big time-saver.