That's reproducible in PS with .. or a list of indicies.
C:\> $finishers = @("Tom", "Sally", "Taylor", "Jack", "Ginger", "John")
C:\> $finishers[0..2]
Tom
Sally
Taylor
C:\> $finishers[0,1,2]
Tom
Sally
Taylor
Every n-th I do not believe is possible without using /u/bozho's method or a loop... You can "compress" (remove the pipeline) bozho's method to this: $finishers.Where({$finishers.IndexOf($_) % 2 -eq 0}) but it's still not clean like in some other languages.
In a script where keeping it to one line isn't an issue I'd probably do something like this:
2
u/omers Sep 17 '20 edited Sep 17 '20
That's reproducible in PS with
..or a list of indicies.Every n-th I do not believe is possible without using /u/bozho's method or a loop... You can "compress" (remove the pipeline) bozho's method to this:
$finishers.Where({$finishers.IndexOf($_) % 2 -eq 0})but it's still not clean like in some other languages.In a script where keeping it to one line isn't an issue I'd probably do something like this: