I decided to golf up this kumite - for the sanity of the tester, I trim the function definition to remove leading or trailing spaces.
Write-Verbose (Get-Module pester -listAvailable).Version.ToString() function calculate_multiples { (1..999|?{!($_%3) -or !($_%5)}|measure -s).sum }
1 + Write-Verbose (Get-Module pester -listAvailable).Version.ToString()
1 1 function calculate_multiples {
2 − 3 − $SUM = 0
4 − 5 − 1..999 | ForEach-Object {
6 − if (!( $_ % 3) -OR !($_ % 5)) {
7 − $Sum += $_
8 − }
9 − }
10 − 11 − return $Sum
3 + (1..999|?{!($_%3) -or !($_%5)}|measure -s).sum
12 12 }
# You can test with Pester (https://github.com/pester/Pester) # TODO: replace with your own tests (TDD), these are just here to demonstrate usage. $Results = calculate_multiples Describe 'My Solution' { It 'Should return 233168' { $Results | Should be 233168 } It 'Should be short' { (get-item Function:\calculate_multiples).Definition.Trim().Length -lt 50 #$true } }
1 1 # You can test with Pester (https://github.com/pester/Pester)
2 2 # TODO: replace with your own tests (TDD), these are just here to demonstrate usage.
3 3 $Results = calculate_multiples
4 4 5 5 Describe 'My Solution' {
6 6 It 'Should return 233168' {
7 7 $Results | Should be 233168
8 8 }
9 + It 'Should be short' {
10 + (get-item Function:\calculate_multiples).Definition.Trim().Length -lt 50
11 + #$true
12 + }
9 9 }