$ puppet apply test.pp
Notice: Scope(Class[main]): [grant, jade, john, emily]
Notice: Compiled catalog for alt01836.csnzoo.com in environment production in 0.03 seconds
Notice: Applied catalog in 0.01 seconds
Created
July 20, 2022 13:31
-
-
Save sandipb/dc71b71b5ba4f34453d08cc3aaaa16ec to your computer and use it in GitHub Desktop.
Puppet sort hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$data = [ | |
{'name'=> 'emily', 'age'=> 6}, | |
{'name'=> 'john', 'age'=> 5}, | |
{'name'=> 'jade', 'age'=> 4}, | |
{'name'=> 'grant', 'age'=> 2}, | |
] | |
function age_sorted_names($ar) >> Array { | |
$ar.map |$idx, $entry| { | |
[$entry['age'], $entry['name']] | |
}.sort.map|$idx, $entry|{ | |
$entry[1] | |
} | |
} | |
age_sorted_names($data).notice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment