Skip to content

Commit 4181e90

Browse files
committed
Utils.Array.Remove would return an incorrect array of removed elements if one of the items to be removed was skipped in the array. Fix phaserjs#5398
1 parent 377d27c commit 4181e90

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

src/utils/array/Remove.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ var SpliceOne = require('./SpliceOne');
88

99
/**
1010
* Removes the given item, or array of items, from the array.
11-
*
11+
*
1212
* The array is modified in-place.
13-
*
13+
*
1414
* You can optionally specify a callback to be invoked for each item successfully removed from the array.
1515
*
1616
* @function Phaser.Utils.Array.Remove
@@ -54,6 +54,7 @@ var Remove = function (array, item, callback, context)
5454
// If we got this far, we have an array of items to remove
5555

5656
var itemLength = item.length - 1;
57+
var removed = [];
5758

5859
while (itemLength >= 0)
5960
{
@@ -65,21 +66,18 @@ var Remove = function (array, item, callback, context)
6566
{
6667
SpliceOne(array, index);
6768

69+
removed.push(entry);
70+
6871
if (callback)
6972
{
7073
callback.call(context, entry);
7174
}
7275
}
73-
else
74-
{
75-
// Item wasn't found in the array, so remove it from our return results
76-
item.pop();
77-
}
7876

7977
itemLength--;
8078
}
8179

82-
return item;
80+
return removed;
8381
};
8482

8583
module.exports = Remove;

0 commit comments

Comments
 (0)