-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotate-Array(Using Arrays).ps1
More file actions
43 lines (30 loc) · 892 Bytes
/
Copy pathRotate-Array(Using Arrays).ps1
File metadata and controls
43 lines (30 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<# Shift the Array on given input as no.of rotations
Output = Array
Input = @(1,2,3,4,5)
5,1,2,3,4
4,5,1,2,3
1) record input - Array, rotations
2) Iterate the array
#>
Function Rotate-Array()
{
param([array]$input_array, [int]$no_of_rotations)
for($i = 0; $i -lt $no_of_rotations; $i++)
{
$len_array = $input_array.Length
$array_element_to_be_rotated = $input_array[$input_array.Length-1]
$Output_array = @()
$Output_array += $array_element_to_be_rotated
for($j = 0; $j -lt $input_array.Length-1; $j++)
{
if($input_array[$j] -ne $Output_array[$j])
{
$Output_array += $input_array[$j]
}
}
$input_array = $Output_array
}
Write-Host "$Output_array"
#return $Output_array
}
Rotate-Array -input_array @(1,2,3,4,5) -no_of_rotations 4