I am looking for the most efficient way to do this. Anything with a hyphen must be in before any symbols without a hyphen in the array. My naive solution filters the array twice and concats. I feel like there should be a way to do this in one pass instead of two.
input = [:en, :de, :es, :"es-MX", :fr, :ko, :"ko-KR", :"en-GB"]
output = [:"es-MX", :"ko-KR", :"en-GB", :en, :de, :es, :fr]
Naive solution:
def reorder(input)
## find everything with a hypen
output = input.select { |l|
l.to_s.include?('-')
}
# find everything without a hyphen and concat to output
output.concat(input.reject { |l|
l.to_s.include?('-')
})
end