How to rotate an array for desired say "K" number of times

How to store an array of elements in a List like A = [3, 8, 9, 7, 6] also

how can I display the array like [9, 7, 6, 3, 8] with comma separated values provided we have an array of integers.


My goal is to Write a function

that, given an array/ list A consisting of N integers and an

integer K, returns the array A rotated K times.

For example, given

A = [3, 8, 9, 7, 6]

K = 3

the function should return [9, 7, 6, 3, 8].

Hi Varada,

It seems you are trying something that's definitely not low code, with a very low code tool that's OutSystems. What is your use case? Why do you need this?

Personally, I would write an Extension if you really must have this behaviour, but it strikes me as something very odd.

Hello varada. 

This seems to be some kind of algorithm test. You can do it in outsystems the same way you do in any other language. First you drfine your algorithm, then you implement it in the language. 

In OutSystems you have lists and you can access (read/write) elements in a position using the index (e.g. MyList[index]) and assign to set values. 

You can execute loopings using foreach, or in your case, using IF. 

Good luck

Thank You

I Solved this logic in strings please check in below link (StringLoop-> enter string -> Give give count )

https://abhilash-eedara.outsystemscloud.com/Logics/Entry1.aspx?_ts=637097007299254298

I want to implement in arrays, but in outsystems instead of arrays we will use List, Please guide me to solve this using list


For exaample: Input= 3,12,4,5,54

k=3

output link 4,5,54,3,12


Hi Abhilash,

You can index lists. Instead of List.Current you use List[index]. Personally I'd create a second list by using ListAppend. Start at the index modulo list length, walk through the original list (with index modulo list length), and append to the new list.

Hello Kilia,

Please share dummy oml to take input like 2,34,53,1 and output is the same as above, using List.

Thank You


Hi Abhilash,

I'll try to upload something in a while, as soon as I can find some time.

Solution

Hi Abhilash,

Here's an example.

Solution

Kilian Hekhuis wrote:

Hi Abhilash,

Here's an example.

Thank you Kilian

You're most welcome. If you have any questions, just let me know. Also, if you find my answer above useful, please mark it as Solution, thanks.