Skip to content

Commit 3fc527b

Browse files
committed
Added Math.numberArray back in and renamed the replacement to Math.numberArrayStep to avoid breaking the API.
1 parent 5e6c40e commit 3fc527b

1 file changed

Lines changed: 51 additions & 18 deletions

File tree

src/math/Math.js

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -516,64 +516,97 @@ Phaser.Math = {
516516

517517
},
518518

519+
/**
520+
* Returns an Array containing the numbers from min to max and inclusive of both values.
521+
* If you need exclusive of max then see Phaser.Math.numberArrayEx.
522+
*
523+
* @method Phaser.Math#numberArray
524+
* @param {number} min - The minimum value the array starts with.
525+
* @param {number} max - The maximum value the array contains.
526+
* @return {array} The array of number values.
527+
*/
528+
numberArray: function (min, max) {
529+
530+
var result = [];
531+
532+
for (var i = min; i <= max; i++)
533+
{
534+
result.push(i);
535+
}
536+
537+
return result;
538+
539+
},
540+
519541
/**
520542
* Creates an array of numbers (positive and/or negative) progressing from
521543
* `start` up to but not including `end`. If `start` is less than `stop` a
522544
* zero-length range is created unless a negative `step` is specified.
523545
*
524546
* @static
525-
* @method Phaser.Math.numberArray
526-
* @param {number} [start=0] The start of the range.
527-
* @param {number} end The end of the range.
528-
* @param {number} [step=1] The value to increment or decrement by.
547+
* @method Phaser.Math#numberArrayStep
548+
* @param {number} [start=0] - The start of the range.
549+
* @param {number} end - The end of the range.
550+
* @param {number} [step=1] - The value to increment or decrement by.
529551
* @returns {Array} Returns the new array of numbers.
530552
* @example
531553
*
532-
* Phaser.Math.numberArray(4);
554+
* Phaser.Math.numberArrayStep(4);
533555
* // => [0, 1, 2, 3]
534556
*
535-
* Phaser.Math.numberArray(1, 5);
557+
* Phaser.Math.numberArrayStep(1, 5);
536558
* // => [1, 2, 3, 4]
537559
*
538-
* Phaser.Math.numberArray(0, 20, 5);
560+
* Phaser.Math.numberArrayStep(0, 20, 5);
539561
* // => [0, 5, 10, 15]
540562
*
541-
* Phaser.Math.numberArray(0, -4, -1);
563+
* Phaser.Math.numberArrayStep(0, -4, -1);
542564
* // => [0, -1, -2, -3]
543565
*
544-
* Phaser.Math.numberArray(1, 4, 0);
566+
* Phaser.Math.numberArrayStep(1, 4, 0);
545567
* // => [1, 1, 1]
546568
*
547-
* Phaser.Math.numberArray(0);
569+
* Phaser.Math.numberArrayStep(0);
548570
* // => []
549571
*/
550-
numberArray: function(start, end, step) {
572+
numberArrayStep: function(start, end, step) {
573+
551574
start = +start || 0;
552575

553576
// enables use as a callback for functions like `_.map`
554577
var type = typeof end;
555-
if ((type == 'number' || type == 'string') && step && step[end] === start) {
578+
579+
if ((type === 'number' || type === 'string') && step && step[end] === start)
580+
{
556581
end = step = null;
557582
}
583+
558584
step = step == null ? 1 : (+step || 0);
559585

560-
if (end == null) {
586+
if (end === null)
587+
{
561588
end = start;
562589
start = 0;
563-
} else {
590+
}
591+
else
592+
{
564593
end = +end || 0;
565594
}
595+
566596
// use `Array(length)` so engines like Chakra and V8 avoid slower modes
567597
// http://youtu.be/XAqIpGU8ZZk#t=17m25s
568-
var index = -1,
569-
length = Phaser.Math.max(Phaser.Math.ceil((end - start) / (step || 1)), 0),
570-
result = new Array(length);
598+
var index = -1;
599+
var length = Phaser.Math.max(Phaser.Math.ceil((end - start) / (step || 1)), 0);
600+
var result = new Array(length);
571601

572-
while (++index < length) {
602+
while (++index < length)
603+
{
573604
result[index] = start;
574605
start += step;
575606
}
607+
576608
return result;
609+
577610
},
578611

579612
/**

0 commit comments

Comments
 (0)