forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEachInRange.js
More file actions
57 lines (47 loc) · 1.54 KB
/
Copy pathEachInRange.js
File metadata and controls
57 lines (47 loc) · 1.54 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Passes each element in the array, between the start and end indexes, to the given callback.
*
* @function Phaser.Utils.Array.EachInRange
* @since 3.4.0
*
* @param {array} array - The array to search.
* @param {function} callback - A callback to be invoked for each item in the array.
* @param {object} context - The context in which the callback is invoked.
* @param {integer} startIndex - The start index to search from.
* @param {integer} endIndex - The end index to search to.
* @param {...*} [args] - Additional arguments that will be passed to the callback, after the child.
*
* @return {array} The input array.
*/
var EachInRange = function (array, callback, context, startIndex, endIndex)
{
var len = array.length;
if (startIndex === undefined) { startIndex = 0; }
if (endIndex === undefined) { endIndex = len; }
if (endIndex > len)
{
endIndex = len;
}
if (startIndex < 0 || startIndex > len || startIndex >= endIndex)
{
throw new Error('Range Error: Values outside acceptable range');
}
var i;
var args = [ null ];
for (i = 5; i < arguments.length; i++)
{
args.push(arguments[i]);
}
for (i = startIndex; i < endIndex; i++)
{
args[0] = array[i];
callback.apply(context, args);
}
return array;
};
module.exports = EachInRange;