I think I need a bit of proof reading or logic check from someone. I can’t find any difference between mine and the Solution no 1 of this challenge but I know for sure that the Solution no 1 works with all the test arrays provided while mine fails with the [“hello”, “hey”] and similar but seems to work with the others.
My loop return the correct index -1 but does not return false (please see screenshots)
Any nudge will be appreciated
Thank you
thank you, I thought about it but then why the solution no1 is right?
Isn’t the return statement in a loop as well?
I may have missed some important information somewhere#
L
function mutation(arr) {
var test = arr[1].toLowerCase();
var target = arr[0].toLowerCase(); for (var i = 0; i < test.length; i++) {
** if (target.indexOf(test[i]) < 0) return false;**
** }**
return true;
}
you have only one return statement inside the for loop, and it is executed only in a specific case: this is because once you know that there is one letter that make the condition false, there is no sense in continuing to check
the other return statement is after the loop
Ok, thank you.
My mistake was the statement in the non Conditional (Ternary) Operator :
(newArr1[i] < 0)) instead of (newArr1[i]) < 0)
In the Ternary operator, well I don’t know if you can use it in this situation