The ol' fashioned way would be to use a reverse loop and compare chars. As soon as a mismatch is found return false.

Simplifying your attempt replace inner if statement with: return (index of...