MCPcopy
hub / github.com/phaserjs/phaser / Remove

Function Remove

src/utils/array/Remove.js:26–81  ·  view source on GitHub ↗
(array, item, callback, context)

Source from the content-addressed store, hash-verified

24 * @return {*|Array.<*>} The item, or array of items, that were successfully removed from the array.
25 */
26var Remove = function (array, item, callback, context)
27{
28 if (context === undefined) { context = array; }
29
30 var index;
31
32 // Fast path to avoid array mutation and iteration
33 if (!Array.isArray(item))
34 {
35 index = array.indexOf(item);
36
37 if (index !== -1)
38 {
39 SpliceOne(array, index);
40
41 if (callback)
42 {
43 callback.call(context, item);
44 }
45
46 return item;
47 }
48 else
49 {
50 return null;
51 }
52 }
53
54 // If we got this far, we have an array of items to remove
55
56 var itemLength = item.length - 1;
57 var removed = [];
58
59 while (itemLength >= 0)
60 {
61 var entry = item[itemLength];
62
63 index = array.indexOf(entry);
64
65 if (index !== -1)
66 {
67 SpliceOne(array, index);
68
69 removed.push(entry);
70
71 if (callback)
72 {
73 callback.call(context, entry);
74 }
75 }
76
77 itemLength--;
78 }
79
80 return removed;
81};
82
83module.exports = Remove;

Callers 4

PluginManager.jsFile · 0.85
ParticleEmitter.jsFile · 0.85
Clock.jsFile · 0.85
Remove.test.jsFile · 0.85

Calls 1

SpliceOneFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…