Skip to content

Instantly share code, notes, and snippets.

@sandipb
Created July 20, 2022 13:31
Show Gist options
  • Save sandipb/dc71b71b5ba4f34453d08cc3aaaa16ec to your computer and use it in GitHub Desktop.
Save sandipb/dc71b71b5ba4f34453d08cc3aaaa16ec to your computer and use it in GitHub Desktop.
Puppet sort hash
$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
$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment