So, I am having a bit of trouble completing this assignment. I have met 3/4 of the requirements, with the only unpassed requirement being “failuresList should be equal to the specified output.” The problem is, I can’t figure out how to get them to match. The output of my code is:
What do you think that is doing? Do you think it is copying the array? It is not, it is copying the reference (memory address) of the array. If I have my house address written down on a piece of paper, and I copy that piece of paper, there is still only one house. It’s just that those two pieces of paper “point” to the same house. Similarly, these two variable now point to the same array in memory. This is often a hard concept for learners to wrap their heads around, very common. Copying primitive types is easy. Copying reference types (objects, arrays, functions, etc.) can get a little tricky.
Then you do this:
failureItems[i] = ...
Now, you are not just changing that one array, you are changing both. That is bad practice - you usually don’t want to change your parameters.
But that is probably not what is causing it to fail.
The instructions say:
Use an iterator method (any kind of loop) …
Perhaps the word “loop” is throwing you off there, but they are clearly asking for a method there. If I rewrite this using one of the array methods (which are really just disguised loops) then it passes for me.
There are a couple of different choices, but there is one array method that specifically makes and returns a new array where each element is based on the corresponding element from the original array.