Text Function - insert() behavior

Certified Lead Developer

I have encountered a weird behavior related to insert() function. My use case is I am trying to insert 3 new values at the top of the list. 

E.g. Initial list is {"W","X","Y","Z"} and I try the insert command like insert({"W","X","Y","Z"},{"A","B","C"},{1,2,3})

But this command doesn't yield the expected result and yields output as {"A", "W", "B", "X", "C", "Y", "Z"}

 

Again I tried like this : insert({"W","X","Y","Z"},{"A","B","C"},{1,1,1}) and output is as expected : {"A", "B", "C", "W", "X", "Y", "Z"}

 

Can someone help me understand why {1,1,1} worked but {1,2,3} didn't?

 

Thanks in advance!

  Discussion posts and replies are publicly visible

Parents
  • Think of the index parameter as the index relative to the original array.
    Given your example:
    "A" precedes "W" because that's position 1 of the original array.
    "B" follows "W" because that would have been the 2nd position of the original array.
    "C" follows "X" because that would have been the 3rd position of the original array.

    Also, The following would put all your values at the top of the list:
    insert({"W","X","Y","Z"},{"A","B","C"},1)
Reply
  • Think of the index parameter as the index relative to the original array.
    Given your example:
    "A" precedes "W" because that's position 1 of the original array.
    "B" follows "W" because that would have been the 2nd position of the original array.
    "C" follows "X" because that would have been the 3rd position of the original array.

    Also, The following would put all your values at the top of the list:
    insert({"W","X","Y","Z"},{"A","B","C"},1)
Children
No Data