I think(["AB", "AAB"]) should not return true because it does not include all of the letters from the other string, it is missing A. Therefore, this code below should be working. Or I’m just stupid.
function mutation(arr) {
let str1 = arr[0].toLowerCase(), str2 = arr[1].toLowerCase();
for (let i = 0; i < str2.length; i++){
if (!str1.includes(str2[i])) {
return false
} else {
str1 = str1.replace(str1[str1.indexOf(str2[i])],"")
}
}
return true;
}
I know I can omit the else statement and got the “correct” result accordingly, my question is whether provided solutions are correct or not to that task assignment.
Return true if the string in the first element of the array = ["AB"] contains all of the letters of the string in the second element of the array. = ["ABB"]=> true where I think it should return false, because:
"AB".length < "ABB".length .
It’s missing "B"
String in the first element does not contain all letters in the string from the second string.
I see this: AB has all kinds of the letters in ABB AB has all kinds of the letters in ABBB AB has all kinds of the letters in ABBBB AB has all kinds of the letters in ABBBBB
It has all kinds of letters, it does not contain all of the letters…
You have created a distinction that does not exist. B is a letter. Writing it twice does not change the fact that B is only one letter. The string AB has the same letters as ABBBBBBBBBBBBBBBBB. Repeating B does not make B anything other than B.
I was looking at this task more like from permutation perspective and perhaps made it more complicated than it was intended.
Nevertheless, I’m going to die with the opinion that the assignment can be misleading