Embarking on the challenging Mars Rover Kata has presented a unique problem for me. My jasmine tests are failing because of my array compare method within the prototype. This method is crucial for detecting obstacles at specific grid points.
For instance, my initial test result shows this error: Expected [ 0, 1, 'N', undefined ] to be equal to [ 0, 1, 'N' ].
Upon logging my array, it displays as [0, 1, "N", compare: function]. This discrepancy explains why it doesn't match with [0, 1, 'N'].
The length of my array is 3 and the proto includes the compare method. How can I address this issue?
Access the code branch here. View the tests here.
Update:
I discovered that one of my conditionals was returning undefined, leading to the error of undefined being inserted into my array. Thanks to @GameAlchemist's solution suggestion, I learned about defineProperty and identified the root cause of the problem.
Moreover, based on my research, it is recommended to use Object.defineProperty() or similar methods when adding properties to built-in prototypes to ensure they are non-enumerable. This safeguard helps prevent issues with for-in loops in older code bases.