重构 Ruby 中嵌套的每个循环
我需要进行比较两个哈希的搜索,
我使用each来迭代哈希,并使用b_search进行二分搜索:
@player.each do |player|
player_support_search = players_support.bsearch { |player_support| player_support[:score] >= player[:score] }
number_player_support_search [player_support_search [:id]] += 1 unless player_support_search .nil?
end
是否有任何模式可以重构为仅使用一个循环?
I need to do a search comparing two hashs
I use an each to iterate over a hash and b_search to do the binary search:
@player.each do |player|
player_support_search = players_support.bsearch { |player_support| player_support[:score] >= player[:score] }
number_player_support_search [player_support_search [:id]] += 1 unless player_support_search .nil?
end
Is there any pattern where I can refactor to use only one loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论