Skip to content

Commit

Permalink
Better arrayAnswers.remove test data
Browse files Browse the repository at this point in the history
Ensure that method works correctly on an array with two of the same value in a row.

For example, this method will pass the test in its current form, but contains a
flaw that is revealed when the test data includes two identical values in a row:

for(var i = 0; i < arr.length; i++) {
    if(arr[i] === item) {
        arr.splice(i, 1);
    }
}
return arr;

By removing arr[i] AND incrementing the index, the loop effectively tests only
every other array item, and will not remove all instances of the tested value.

[close rmurphey#185]
  • Loading branch information
Lauren Brandstein authored and Rebecca Murphey committed May 28, 2016
1 parent 50e02df commit 8be6769
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions tests/app/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('arrays', function() {

it('you should be able to remove all instances of a value from an array', function() {
a.push(2); // Make sure the value appears more than one time
a.push(2); // Make sure the value appears more than one time in a row
var result = arraysAnswers.remove(a, 2);

expect(result).to.have.length(3);
Expand Down

0 comments on commit 8be6769

Please sign in to comment.