This Challenge requires 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.
For example,
["hello", "Hello"]
, have to return true because all of the letters in the second string are present in the first, after ignoring case.
The arguments
["hello", "hey"]
should have to return false because the string in first element "hello" does not contain a "y".
Similarly,
["Alien", "line"]
, should be returning true because all of the letters in "line" are there in "Alien".
Clue in the form of helpful links is as given below. Its a clickable link leading to MDN documentation to study more about the string method indexOf():
Again using a little trail & error and the Read-Search-Ask technique. I can up with following solution.
Again using a little trail & error and the Read-Search-Ask technique. I can up with following solution.
function mutation(arr) {
var a = arr[0].toLowerCase();
var b = arr[1].toLowerCase();
if (a === b) {
return true;
} else {
var c = b.split("");
var i = 0;
for (var j = 0; j < b.length; j++){
i = a.indexOf(c[j]);
if (i === -1)
break;
}
if (i !== -1){
return true;
} else {
return false;
}
}
}
No comments:
Post a Comment