Created
March 11, 2013 16:01
-
-
Save pcarrier/5135288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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