Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$list = @"
1 Partridge in a pear tree
2 Turtle Doves
3 French Hens
4 Calling Birds
5 Golden Rings
6 Geese a laying
7 Swans a swimming
8 Maids a milking
9 Ladies dancing
10 Lords a leaping
11 Pipers piping
12 Drummers drumming
"@
$birdCollection = @("Birds","Doves", "Geese", "Hens", "Partridge","Swans")
$verseCollection = $list -split "`n" | ForEach-Object -Process {
$dayOfXmas = New-Object -TypeName psobject
if($_ -match "(\d+\s+)([\s\S]+)"){
$dayOfXmas |
Add-Member -MemberType NoteProperty -Name Day -Value $Matches[1] -PassThru |
Add-Member -MemberType NoteProperty -Name Lyric -Value $Matches[2] -PassThru
}
}
$verseCollection | Select-Object -Property Day, Lyric, @{l='Length';e={$_.Lyric.Length}}|
Sort-Object -Property Length | Select-Object -Property Lyric
$countBirdsRef = 0
$verseCollection | ForEach-Object {$_.Lyric -split "\s+"} |
ForEach-Object -Process {
if($birdCollection -contains $_){$countBirdsRef++}
}
$cumulativeGiftCount = 0
$intrnlIterator = 0
$verseCollection.Day | ForEach-Object -Process {
$intrnlIterator += ($_ -split "\s" | Measure-Object -Sum).Sum
$cumulativeGiftCount += $intrnlIterator
}
"*"*50
"Bird References = {0}" -f $countBirdsRef
"Total count = {0}" -f ($verseCollection | Measure-Object -Property Day -Sum).Sum
"Cumulative Gift Count = {0}" -f $cumulativeGiftCount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment