Mutations Challenge -- Instructions are complete?

The instructions say…

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.

And then the instructions go on to give examples that fit the above definition - namely, the all the chars in the second array element can be found in the the chars of the first array element…

The instructions do not say…

Return true if the string in the second element of the array contains all of the letters of the string in the first element of the array.

The above is the opposite or inverse of what the instructions say; but, judging from the console output, this is in fact expected from the code.

// For Example..

["Mary", "Aarmy"]

// All of the chars in the second element can not be found in the
// first element - violating what IS stated in the instructions.
// However, all of the chars in the first element CAN be found in
// the second element - the reverse of what is found in the
// instructions (or not mentioned).

Compare the above example with the corresponding output in the console.

See screenshot at the bottom of this post (which shows the output in the console).

This code in onecompiler

The code below fits what is included in the instructions (it does not fit what is not included in the instructions). Nevertheless, the code below fails because it does not fit what is not included in the instructions?

Your code so far


function mutation(arr) {
  
arr[0] = arr[0].toLowerCase().split('');
arr[1] = arr[1].toLowerCase().split('');

for (let i = 0; i < arr.length; i++) {
  arr[i].sort( function( a , b){
    if(a > b) return 1;
    if(a < b) return -1;
    return 0;
  });
}

arr[0] = arr[0].join('');
arr[1] = arr[1].join('');

return arr[0].includes(arr[1]);
}

mutation(["hello", "hey"]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0

Challenge: Mutations

Link to the challenge:

Correction, while the above remains true, there are (apparently) other flaws in the code as it is.

Nevertheless the requirement for mutation(["Mary", "Aarmy"]) was not expected

At this point I’m basically stuck and about to call it a night soon. Not because of the case stated above but because of the other two cases (alphabetical sorting and looking for a substring do not work in these other two cases)…

mutation(["floor", "for"])
mutation(["Noel", "Ole"])

Please show me a letter that is in Aarmy that is not found in Mary. (Recalling that case does not matter)

Post must be at least 20 characters…

The other a

Where do the instructions say that the each letter must show the exact same number of times? That would be an interesting challenge, but a completely different one.

They don’t…

Neither do they

In other words - it is not specified either way and is left to the reader.

Personally? I interpreted it in the way I was describing

  1. That element 2 was to be found in element 1 and not the other way around (exclusive)
  2. Not that the number of letters needed to match but that element 1 was to be found in element 2 when they didn’t.

You added an extra requirement. Adding extra requirements that contradict the test cases is never left as an option to the reader!! When in doubt, look at the test cases - they are examples to help show you what is expected.

The challenge expects you to take the requirement at face value - return true if every letter in the second word can be found in the first word, or conversely return false is there exists a letter in the second word that cannot be found in the first word.

Well I get what you are saying but the instructions (as they are worded) make a point of ordering (element 2, element 1) and defining that ordering as element 2 being found in element 1 - I did not add that to the instructions - it is there.

When I read something that is explicitly ordering elements and describing the requirement as one coming from the other then that is exactly how I interpret it - literally.

the string in the first element

^ That is ordination

string in the second element

^ That is ordination

the string in the first element of the array contains

^ That is speaking of one coming from the other (in a specific order)

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.

Is logically identical to

Return true if all of the letters of the string in the second element of the array are contained in the string in the first element of the array.

Is logically identical to

Return false if at least one of the letters of the string in the second element of the array is not contained in the string in the first element of the array.

Is logically identical to

Return false if the string in the first element of the array does not contain all of the letters of the string in the second element of the array.

This is boolean logic.


It’s OK that you misunderstood what you read. But the instructions and the test cases are logically consistent.

I didn’t come here for an argument and I don’t want to put a strain on any future relationship we may have. I appreciate fCC and what you guys do - but that is not the point here. Now the choices available to me are to either agree with something that is clearly an oversight or to try one last time to point out the obvious.

The concept of ordination (mathematical ordination) comes into play when you enumerate something. I am not talking about the general nature of arrays since that is not what is being addressed in the instructions. Yes, the logical equivalents you present are true - however, they do not exclude the fact that the instruction clearly gives order to which string comes from which (ordination - not in the nature of arrays but specifically and clearly prescribing an order to the requirements).

Now I don’t care who’s wrong or who’s right when it comes to passing the test - I’m gonna create code that works and pass it whatever that takes. The only reason I took so much time creating this post and all the replies was because I care about the fCC community and wanted to help by pointing out something that is inconsistent in a challenge. If anyone can read that first paragraph of those instructions word-for-word and not see the order in what is being prescribed then I applaud that!

I’m sorry. You are misinterpreting the instructions. It happens sometimes.

The instructions are logically valid. There is no problem with the order of the clauses.

mutation([“ate”, “date”]) should return false.

mutation([“floor”, “for”]) should return true.

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

In each of these cases, the function returns true only if the first word contains all letters from the second word.

In other words, each letter in the second word can be found in the first word.

I’ve studied logic and mathematics for almost twenty years of my life? I might know a thing or two?

Those facts are not coming from the written instruction. It comes from experiencing the result of running the code. There’s a difference.

A lot of us have gone to college (and continued to practice what we learned).

Again, I’m sorry you misunderstood the instructions, but the statement in the instructions is logically consistent with the results in the tests.

The only way to correctly interpret the instructions is literally as given or in any one the logically equivalent forms I provided.

If you prefer mathematical-esk notation, the instructions literally say
[A, B] => A ⊇ B
Or
“A contains everything that B contains”

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.