Krug.ArrayUtil (Krug v0.4.11) View Source

Utilitary module to handle array transformations.

Link to this section Summary

Functions

Rotates an array X positions in direction from right to left. A initial array [1,2,3,4] turn in [4,1,2,3] if rotate positions equal to 1.

Rotates an array X positions in direction from left to right. A initial array [1,2,3,4] turn in [2,3,4,1] if rotate positions equal to 1.

Link to this section Functions

Link to this function

rotate_left(array, positions)

View Source (since 0.4.3)

Rotates an array X positions in direction from right to left. A initial array [1,2,3,4] turn in [4,1,2,3] if rotate positions equal to 1.

Examples

iex > Krug.ArrayUtil.rotate_left(nil,1)
nil
iex > Krug.ArrayUtil.rotate_left([],1)
[]
iex > Krug.ArrayUtil.rotate_left([1],2)
[1]
iex > Krug.ArrayUtil.rotate_left([1,2,3,4],1)
[4,1,2,3]
iex > Krug.ArrayUtil.rotate_left([1,2,3,4],3)
[2,3,4,1]
Link to this function

rotate_right(array, positions)

View Source (since 0.4.3)

Rotates an array X positions in direction from left to right. A initial array [1,2,3,4] turn in [2,3,4,1] if rotate positions equal to 1.

Examples

iex > Krug.ArrayUtil.rotate_right(nil,1)
nil
iex > Krug.ArrayUtil.rotate_right([],1)
[]
iex > Krug.ArrayUtil.rotate_right([1],2)
[1]
iex > Krug.ArrayUtil.rotate_right([1,2,3,4],nil)
[1,2,3,4]
iex > Krug.ArrayUtil.rotate_right([1,2,3,4],1)
[2,3,4,1]
iex > Krug.ArrayUtil.rotate_right([1,2,3,4],3)
[4,1,2,3]