Skip to content

How to sort an array of hashes by the value of a specific key of the hash? #17

Answered by b4ldr
c33s asked this question in Q&A
Discussion options

You must be logged in to vote

you can use the following in puppet >= 6 or with puppetlabs-stdlib

[{'order' => 1}, {'order' => 3}, {'order' => 2}].sort |$a, $b| { compare($a['order'], $b['order'])  }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by c33s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants