Skip to content

Commit 92bac85

Browse files
committed
Optimize the average function in math.js
1 parent 482d3c9 commit 92bac85

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/math/Math.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@ Phaser.Math = {
9898
*/
9999
average: function () {
100100

101-
var sum = 0;
101+
var sum = 0,
102+
argumentsLength = arguments.length;
102103

103-
for (var i = 0; i < arguments.length; i++) {
104+
for (var i = 0; i < argumentsLength; i++) {
104105
sum += (+arguments[i]);
105106
}
106107

107-
return sum / arguments.length;
108+
return sum / argumentsLength;
108109

109110
},
110111

@@ -146,7 +147,7 @@ Phaser.Math = {
146147
/**
147148
* Snap a value to nearest grid slice, using floor.
148149
*
149-
* Example: if you have an interval gap of 5 and a position of 12... you will snap to 10.
150+
* Example: if you have an interval gap of 5 and a position of 12... you will snap to 10.
150151
* As will 14 snap to 10... but 16 will snap to 15.
151152
*
152153
* @method Phaser.Math#snapToFloor

0 commit comments

Comments
 (0)