find方法

简介:
对数组进行find方法寻找适合条件的元素,等价于用for循环数组,得出满足条件的元素
find方法是种迭代器
InBlock.gif def with_title(title)
InBlock.gif     for i  in 0...@songs.length
InBlock.gif       return @songs[i]  if title==@songs[i].name
InBlock.gif    end
InBlock.gif     return nil
InBlock.gif  end
InBlock.gif  #<=>
InBlock.gif  def with_title(title)
InBlock.gif    @songs.find{|song| title==song.name}




本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/64011,如需转载请自行联系原作者
目录
相关文章
运行wpscan报错Could not find 'nokogiri' (~> 1.8.0)
运行wpscan报错Could not find 'nokogiri' (~> 1.8.0)
102 0
find
find
65 0
|
算法 容器
常用查找算法 find() find_if() adjacent_find() binary_search() count() count_if()
常用查找算法 find() find_if() adjacent_find() binary_search() count() count_if()
Find a way
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.
128 0
|
安全 Shell