find方法

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




本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/64011,如需转载请自行联系原作者
目录
相关文章
find
find
90 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.
143 0
|
安全 Shell