Part of your problem is the use of split(’’) on the following line:
If we look at the test case of:
a is an array which looks like [ ‘h’, ‘e’, ‘l’, ‘l’, ‘o’ ]
b.split("") is an array of one element which looks like [ ‘h’ ]
When you write:
you are trying to find the index of an element in a (an array of string character) which is equal to [ ‘h’ ] which is an array of one string. An array is never going to be equal to a string, so this will return -1 and so the if statement evaluates to false, so you return false based on the return false statement following your if.
A secondary issue you will face (once you figure out you are making the wrong comparison above), is that your for loop will only iterate through one time, because you you execute a return statement (true or false). Once a return statement is executed, the for loop and the function are exited and nothing else happens.