forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplace.js
More file actions
37 lines (33 loc) · 1020 Bytes
/
Copy pathReplace.js
File metadata and controls
37 lines (33 loc) · 1020 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
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Replaces an element of the array with the new element.
* The new element cannot already be a member of the array.
* The array is modified in-place.
*
* @function Phaser.Utils.Array.Replace
* @since 3.4.0
*
* @param {*} oldChild - The element in the array that will be replaced.
* @param {*} newChild - The element to be inserted into the array at the position of `oldChild`.
*
* @return {boolean} Returns true if the oldChild was successfully replaced, otherwise returns false.
*/
var Replace = function (array, oldChild, newChild)
{
var index1 = array.indexOf(oldChild);
var index2 = array.indexOf(newChild);
if (index1 !== -1 && index2 === -1)
{
array[index1] = newChild;
return true;
}
else
{
return false;
}
};
module.exports = Replace;