I think I may have been looking at this for too long…would appreicate it if someone could tell me where I’m going wrong here…
function mutation(arr) {
let mainString = arr[0].toLowerCase();
let testLetters = arr[1].toLowerCase();
console.log(mainString);
console.log(testLetters);
for(let i = 0; i > mainString.length; i++) {
if(mainString.indexOf(testLetters[i]) < 0) {
return false;
}
}
return true;
}
mutation([“hello”, “hey”]);
Can you format your code and add a link to the exercise?
function mutation(arr) {
let mainString = arr[0].toLowerCase();
let testLetters = arr[1].toLowerCase();
console.log(mainString);
console.log(testLetters);
for(let i = 0; i > mainString.length; i++) {
if(mainString.indexOf(testLetters[i]) < 0) {
return false;
}
}
return true;
}
mutation([“hello”, “hey”]);
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations
Apologies - here you go. Thanks!
One error I see is here.
i > mainString.length doesn’t make sense because 0 can’t be greater than mainString.length, therefore your forloop will never execute.
1 Like
So simple! Thanks @shimphillip!
I have a bit of a blind spot with greater than and less than - I usually try both just to check. Can’t believe I didn’t here!
Thanks again - appreicate your help.
Hi, what if testLetters is longer than mainString?
Perhaps you should replace mainString.length with testLetters.length
1 Like