This is code I found that splits an array into odd or even results.
$f=0; $array | % { if($f = !$f) { $_ } }
The part I don’t understand is the if statement. Specifically $f=!$f.
The way I’m reading it is if(0 = not 0). The result should always be true since it’s using = and not -eq. I’m sure it’s something simple I’m missing, but I can’t find any info on it.
If anyone has any good resources to read that goes further into this type of logic I’d also love to read more on it.
>Solution :
It’s showing every odd array element. $f goes back and forth from $true to $false. The value of the assignment is what’s on the left side. I would start with $f = $false, to make it a little more clear.
!0
True
!$true
False
$array = 1..10
$f=0; $array | % { if($f = !$f) { $_ } }
1
3
5
7
9