Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
caldulate sum of odd number with powershell
# method + binary
(1..100).Where{($_ -band 1) -eq 0} | Measure -Sum
# pipeline + binary
1..100 | Where {($_ -band 1) -eq 0} | Measure -Sum
# method + division
(1..100).Where{[int]($_ / 2) * 2 -eq $_} | Measure -Sum
# pipeline + division
1..100 | Where{[int]($_ / 2) * 2 -eq $_} | Measure -Sum
# method + modulo
(1..100).Where{$_ % 2 -eq 0} | Measure -Sum
# pipeline + modulo
1..100 | Where {$_ % 2 -eq 0} | Measure -Sum
# method + shift
(1..100).where{($_ -shr 1) -shl 1 -eq $_} | Measure -Sum
# pipeline + shift
1..100 | where {($_ -shr 1) -shl 1 -eq $_} | Measure -Sum
@guitarrapc

This comment has been minimized.

Copy link
Owner Author

guitarrapc commented Aug 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.