reorder array by "shifting" positions

   1141   2   2
User Avatar
Member
1007 posts
Joined: April 2017
Offline
Hi!

I have an array like this:

{value_A, value_B, value_C, value_D, value_E, value_F, value_G}

I found the index of the value that should be first (value_D) and I would like everything to “shift” like this:

(value_D, value_E, value_F, value_G, value_A, value_B, value_C)

Is there a function for that?

-Olivier
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
Hi!

I think there is no function, But you can simply do this with Slicing Array and Push function !!!


s[]@source = {"val_A","val_B","val_C","val_D","val_E","val_F"};

int index = 3;
s[]@new = @source[index:];
push(@new,@source[:index]);
Edited by Sadjad Rabiee - Dec. 18, 2018 20:33:19
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
1007 posts
Joined: April 2017
Offline
Interesting!

I didn't know you could use ":" in brackets. That's a cool trick I'm sure to use later.

Thanks!

-Olivier
  • Quick Links