forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpliceOne.js
More file actions
37 lines (30 loc) · 674 Bytes
/
Copy pathSpliceOne.js
File metadata and controls
37 lines (30 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Removes a single item from an array and returns it
// without creating gc (like the native splice does)
// Based on code by Mike Reinstein
/**
* [description]
*
* @function Phaser.Utils.Array.SpliceOne
* @since 3.0.0
*
* @param {array} array - [description]
* @param {integer} index - [description]
*
* @return {any} [description]
*/
var SpliceOne = function (array, index)
{
if (index >= array.length)
{
return;
}
var len = array.length - 1;
var item = array[index];
for (var i = index; i < len; i++)
{
array[i] = array[i + 1];
}
array.length = len;
return item;
};
module.exports = SpliceOne;