Skip to content

Instantly share code, notes, and snippets.

@pcarrier
Created March 11, 2013 16:01
Show Gist options
  • Select an option

  • Save pcarrier/5135288 to your computer and use it in GitHub Desktop.

Select an option

Save pcarrier/5135288 to your computer and use it in GitHub Desktop.
def find_first a, b
0.upto(a.length-b.length) do |i|
catch :fail do
0.upto(b.length-1) do |j|
throw :fail unless a[i+j] == b[j]
end
return i
end
end
nil
end
find_first %w[a b c d], %w[c d]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment