[BUG] - JS Basic Algorithms: Slice and Splice solution should not pass
See original GitHub issueDescribe your problem and how to reproduce it:
While helping a camper with their work on this solution, I took a look at mine and discovered it passes when it should not.
function frankenSplice(arr1, arr2, n) {
const result = [...arr2.splice(0, n), ...arr1, ...arr2];
console.log(arr1, arr2)
return result
}
console.log(frankenSplice([1, 2, 3], [4, 5, 6], 1));
If you paste this code into the editor, you can see that arr2
has been modified from [4, 5, 6]
to [5, 6]
but the test does not catch this fact.
I believe it may be due to the tests for array modification calling the function without an n
parameter:
- text: The first array should remain the same after the function runs.
testString: frankenSplice(testArr1, testArr2); assert.deepEqual(testArr1, [1, 2]);
- text: The second array should remain the same after the function runs.
testString: frankenSplice(testArr1, testArr2); assert.deepEqual(testArr2, ["a", "b"]);
If I assign a default value of n=1
in the function, then the tests catch this behaviour as expected. As such, I believe updating these function calls in the tests should correct this error.
Add a Link to the page with the problem:
Javascript: Basic Algorithms - Slice and Splice
Tell us about your browser and operating system:
- Browser Name: Chrome
- Browser Version: 85.0.4183.102
- Operating System: Windows 10 v 1909
If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box):
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Yes, updating the test call to:
should correct this bug
So, to be clear @nhcarrigan - you are thinking to put a value in for
n
on those two tests you shared would catch this.