Basic Algorithm Scripting - Mutations

Tell us what’s happening:

I can’t figure out why this problem needs to check for false then return true instead of the inverse if it returns a value greater than or equal to 0. I initially did it this way, where it checked

for (let i = 0; i < test.length; i++) {
    if (target.indexOf(test[i]) >= 0) {
      return true;
    }
  }
  return false;
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

Basic Algorithm Scripting - Mutations

A return statement immediately stops a function. So if you have return true inside of the loop, the very first time that a valid string is found, the function would return immediately and stop checking any other strings.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.