Please can someone help me understand why curly braces were not used in the if statement below:
function mutation(arr) {
let target = arr[0].toLowerCase();
let test = arr[1].toLowerCase();
for (let i = 0; i < test.length; i++) {
if (target.indexOf(test[i]) == -1)
return false
}
return true
}
console.log(mutation(["Hello", "hey"]));
I tried including curly braces and making it an if /else statement but it did not work which was one of the reasons I was finding it difficult to solve this question.
function mutation(arr) {
let target = arr[0].toLowerCase();
let test = arr[1].toLowerCase();
for(let i = 0; i < test.length; i++){
if(target.indexOf(test[i]) == -1){
return false
} else {
return true
}
}
}
console.log(mutation(["Hello", "hey"]));
I found a similar question that was already asked but it did not seem to answer the question.
Please anyone know the reason why this is happening because I feel if I don’t understand this now it might lead to some unrecognized errors in the future.
I am working on the Mutations challenge on the Basic Algorithm Scripting which asked to return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.