If you are not wanting to assign the lowercase versions of arr[0] and arr[1] to variables names, then you could just go with the following and skip the creation of the myArr variable. Strings also have an indexOf function. I am not recommending the following code, because it does not read as well as having variable names for the two elements in arr.
function mutation(arr) {
arr[0] = arr[0].toLowerCase();
arr[1] = arr[1].toLowerCase();
for (var i = 0; i < arr[1].length; i++) {
if (arr[0].indexOf(arr[1][i]) < 0) {
return false;
}
}
return true;
}
Thank you for your reply. Adding lowercase versions are the part of challenge, that’s why I’ve added them. Here is the challenge:
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.
For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case.
The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y".
Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien".
Remember to use Read-Search-Ask if you get stuck. Write your own code.
I know the challenge. I did not say anything about not using the lowercase function. I only said you could remove the following line in your posted code and use the arr[1] in your code instead of myArr.
May be i was not clear, I just need opinion to do it with best practice. If i skip the lowercase then it will not show me h == H. That’s why looking for help. What will be the best practice if i skip the lowercase, then how can i evaluate the lower & upper case?