Check if the first string contains all the letters of the second string:
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
.
The problem that I am facing is that the code produces false
for ["Mary", "Aarmy"]
which it should not do!
function mutation(arr) {
for(let i in arr){
arr[i]=arr[i].toLowerCase().split('').sort().join('');
}
let i=0, j=0, cnt=0;
for(i;i<arr[0].length;i++){
for(j;j<arr[0].length;j++){
if(arr[0][i]==arr[1][j]){
cnt++;
continue;
}
break;
}
}
if(cnt==arr[1].length) return true;
return false;
}
mutation(["Mary", "Aarmy"]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.57
.
Challenge: Mutations
Link to the challenge: