phaser/src/utils/array/RotateLeft.js

35 lines
901 B
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2016-12-07 13:34:21 +00:00
/**
2018-01-26 14:23:00 +00:00
* Moves the element at the start of the array to the end, shifting all items in the process.
* The "rotation" happens to the left.
2017-10-12 12:57:55 +00:00
*
* @function Phaser.Utils.Array.RotateLeft
* @since 3.0.0
*
* @param {array} array - The array to shift to the left. This array is modified in place.
* @param {integer} [total=1] - The number of times to shift the array.
*
2018-03-20 16:15:49 +00:00
* @return {*} The most recently shifted element.
2017-10-12 12:57:55 +00:00
*/
2016-12-07 13:34:21 +00:00
var RotateLeft = function (array, total)
{
if (total === undefined) { total = 1; }
var element = null;
for (var i = 0; i < total; i++)
{
element = array.shift();
array.push(element);
}
return element;
};
module.exports = RotateLeft;