按字母顺序排序的Ruby,但在末尾大写单词的数组 [英] Sort an array alphabetically in Ruby but with capitalised words at the end
本文介绍了按字母顺序排序的Ruby,但在末尾大写单词的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Ruby中按字母顺序排序的字符串。问题是,它把大写单词在字符串的开始,但我希望他们在最后。
I'm trying to sort a string alphabetically in Ruby. The problem is, it puts the capitalized words at the beginning of the string, but I want them at the end.
我原来的字符串是: [苹果,香蕉,斑马,橙色]
我要什么: [香蕉,橙色,苹果,斑马]
推荐答案
交换排序的情况:
["Apple", "banana", "Zebra", "orange"].sort_by(&:swapcase)
#=> ["banana", "orange", "Apple", "Zebra"]
这篇关于按字母顺序排序的Ruby,但在末尾大写单词的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文