Array Searching code challenge
        Posted  
        
            by RCIX
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by RCIX
        
        
        
        Published on 2009-07-03T10:29:22Z
        Indexed on 
            2010/06/13
            14:22 UTC
        
        
        Read the original article
        Hit count: 378
        
Here's my (code golf) challenge: Take two arrays of bytes and determine if the second array is a substring of the first. If it is, output the index at which the contents of the second array appear in the first. If you do not find the second array in the first, then output -1.
Example Input: { 63, 101, 245, 215, 0 } { 245, 215 }
Expected Output: 2
Example Input 2: { 24, 55, 74, 3, 1 } { 24, 56, 74 }
Expected Output 2: -1
Edit: Someone has pointed out that the bool is redundant, so all your function has to do is return an int representing the index of the value or -1 if not found.
© Stack Overflow or respective owner