Misleading task assignment?

Basic Algorithm Scripting: Mutations link here

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;
}


From the challenge text. The first item should contain all of the letters from the second item.
“AAB” does contain all of the letters from “AB”.

(["AAB", "AB"]) => true
(["AB", "AAB"]) => true // I am missing the other A here

this is one of the tests:

mutation(["Mary", "Aarmy"]) should return true.

it seems you are getting the correct result based on challenge logic

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. :wink:

then I don’t understand, please expand

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.

B and B are the same letter. Duplication does not mean that the two are different letters.

AB has all of the letters in ABB
AB has all of the letters in ABBB
AB has all of the letters in ABBBB
AB has all of the letters in ABBBBB

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 :smiley:

That’s why we include sample test cases as well, to help clarify is there is any linguistic misunderstanding.

1 Like