【发布时间】:2013-04-14 10:08:24
【问题描述】:
假设我有一个单词数组,不同的单词可能有不同的长度,我想按长度组织它们。所以稍后我可以通过给出长度参数来访问所有具有相同长度的单词。
words = Array.new()
#fill words by reading file
words.each do |word|
#add word to hash table, key is the length of this word
#what can I do?
end
我已经检查了堆栈溢出中的其他问题和答案,但没有一个人告诉我们如何在旧键下插入一个新值,同时将它们全部保存在数组形式中。
【问题讨论】: