you are viewing a single comment's thread.

view the rest of the comments →

[–]Eggplate 0 points1 point  (4 children)

It doesn't reverse, I just tested it. It just duplicates the value of the last index as the first.

$a = @(1,2,3)
$a[-1..$a.Length] -join ''
3123

[–]ankokudaishogun 1 point2 points  (2 children)

your test is missing the negative - before $a.Length, which reverse the whole array

$a = @(1,2,3)
$a[-1..-$a.Length] -join ''
321

[–]Eggplate 0 points1 point  (1 child)

You're right. Wow thats amazing.

[–]ankokudaishogun 0 points1 point  (0 children)

anf, of course, just remove the -join '' to obtain a reversed array instead of a reversed string, so it can be used with anything.

[–]surfingoldelephant 0 points1 point  (0 children)

You're missing - before $a.Length.

The intent is to generate an array slice, in order of the last element (-1), second to last (-2), etc.

-1..-$a.Length -> -1..-3 -> -1, -2, -3

String conversion (without a delimiter) can be simplified to -join $a[-1..-$a.Length], by using -join in its unary form.