It appears that I ought to be able to swap the last two items in a text array using
Array=arrayrelocate(Array,-1,-2,Separator)
i.e. move the last item (position -1) to be the penultimate item -2) — or vice-versa.
I can swap the penultimate and antepenultimate items, e.g.
arrayrelocate("A,B,C,D,E",-2,-3,",") => A,B,D,C,E
arrayrelocate("A,B,C,D,E",-3,-2,",") => A,B,D,C,E
but if either position parameter is -1, the function results in an error:
arrayrelocate("A,B,C,D,E",-2,-1,",") => new item position is beyond end of array
arrayrelocate("A,B,C,D,E",-1,-2,",") => original item position is beyond end of array
Adding the optional ‘count’ parameter before the separator doesn’t help.
There are other ways to achieve this which do work, e.g.
yoke(arrayrange(Array,1,-3,Separator),Separator,array(Array,-1,Separator)+Separator+array(Array,-2,Separator))
(the yoke
function is needed in case the array has only two elements.) However, if arrayrelocate(
worked as documented it would be an improvement on that, and, if used within a loop, hopefully quicker.
This is using version 10.2.0.b13 (3609).