I want to find the first index of multiple element...
# codereview
t
I want to find the first index of multiple elements in an array. So in [a,b,c,d,a,b,e,f,g,h] I want to search for [b,e] and have index 5 returned. I have this method in Java, before porting it to Kotlin, is there any easier way to do this in Kotlin?
Copy code
public static int indexOf(byte[] outerArray, byte[] smallerArray) {

        if (outerArray == null || smallerArray == null || outerArray.length == 0 ||
                smallerArray.length == 0 || outerArray.length < smallerArray.length) {
            // Guard against input that might throw  nasty runtime exceptions!
            return -1;
        }

        for (int i = 0; i < outerArray.length - smallerArray.length + 1; ++i) {
            boolean found = true;
            for (int j = 0; j < smallerArray.length; ++j) {
                if (outerArray[i + j] != smallerArray[j]) {
                    found = false;
                    break;
                }
            }
            if (found) {
                return i;
            }
        }

        return -1;
    }