小编use*_*148的帖子

用于在两个字段上排序的Ruby习语

我需要Ruby习语在两个字段上进行排序.在Python中,如果对两元素元组的列表进行排序,它将根据第一个元素进行排序,如果两个元素相等,则排序基于第二个元素.

一个例子是来自http://www.pythonlearn.com/html-008/cfbook011.html的 Python中的以下排序代码(从最长到最短的单词排序并考虑断开关系的第二个元素)

txt = 'but soft what light in yonder window breaks'
words = txt.split()
t = list()
for word in words:
   t.append((len(word), word))

t.sort(reverse=True)

res = list()
for length, word in t:
    res.append(word)

print res
Run Code Online (Sandbox Code Playgroud)

我在Ruby中提出的是以下使用结构的代码

txt = 'but soft what light in yonder window breaks'
words = txt.split()
t = []

tuple = Struct.new(:len, :word)
for word in words
    tpl = tuple.new
    tpl.len = word.length
    tpl.word =  word
    t << tpl
end

t = t.sort {|a, …
Run Code Online (Sandbox Code Playgroud)

ruby sorting

2
推荐指数
1
解决办法
665
查看次数

Meteor React Tutorial第2步不起作用

我正在做Meteor React simple-todos教程.第一步是创建应用程序,cd进入app目录并运行meteor.到现在为止还挺好.

我按照步骤2中的说明进行了更改,但未显示待办事项列表.我得到一个空白的屏幕.

代码与https://www.meteor.com/tutorials/react/components上的给出完全相同 没有错误消息显示在浏览器或控制台中.

版本:Meteor 1.5.2.1,OS = Ubuntu 16.04 LTS

meteor meteor-react

2
推荐指数
1
解决办法
830
查看次数

标签 统计

meteor ×1

meteor-react ×1

ruby ×1

sorting ×1