I'm trying to sort an array of phrases in Esperanto by alphabetical order. Is there a way to use sort_by
to accomplish this?
I'm checking each character of the string against its index in the Esperanto alphabet, with each increasing index being a step lower in sorting priority:
esp_alph = " abcĉdefgĝhĥijĵklmnoprsŝtuŭvz"
arr.sort_by {|string|
[esp_alph.index(string[0]),
esp_alph.index(string[1]),
esp_alph.index(string[2]),
esp_alph.index(string[3])]}
However, this isn't a scalable solution, and it breaks if I have more conditions than I have characters in my string. It seems like I'm right at the cusp of a loop based on my string length, but I can't figure out how to implement it without syntax errors. Or is there a better way to go about solving this issue?
end
doing? – Bureaucratic