-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
RemoveAt.js
45 lines (38 loc) · 1.24 KB
/
RemoveAt.js
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
38
39
40
41
42
43
44
45
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var SpliceOne = require('./SpliceOne');
/**
* Removes the item from the given position in the array.
*
* The array is modified in-place.
*
* You can optionally specify a callback to be invoked for the item if it is successfully removed from the array.
*
* @function Phaser.Utils.Array.RemoveAt
* @since 3.4.0
*
* @param {array} array - The array to be modified.
* @param {number} index - The array index to remove the item from. The index must be in bounds or it will throw an error.
* @param {function} [callback] - A callback to be invoked for the item removed from the array.
* @param {object} [context] - The context in which the callback is invoked.
*
* @return {*} The item that was removed.
*/
var RemoveAt = function (array, index, callback, context)
{
if (context === undefined) { context = array; }
if (index < 0 || index > array.length - 1)
{
throw new Error('Index out of bounds');
}
var item = SpliceOne(array, index);
if (callback)
{
callback.call(context, item);
}
return item;
};
module.exports = RemoveAt;