Skip to content

Commit b4a72b8

Browse files
committed
Merge pull request phaserjs#2025 from rwrountree/dev
Optimize the average function in math.js
2 parents 31d6c4d + f017db8 commit b4a72b8

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/math/Math.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Phaser.Math = {
7070
*
7171
* @param {number} val
7272
* @param {number} [epsilon=(small value)]
73-
* @return {boolean} ceiling(val-epsilon)
73+
* @return {number} ceiling(val-epsilon)
7474
*/
7575
fuzzyCeil: function (val, epsilon) {
7676
if (epsilon === undefined) { epsilon = 0.0001; }
@@ -82,7 +82,7 @@ Phaser.Math = {
8282
*
8383
* @param {number} val
8484
* @param {number} [epsilon=(small value)]
85-
* @return {boolean} floor(val-epsilon)
85+
* @return {number} floor(val+epsilon)
8686
*/
8787
fuzzyFloor: function (val, epsilon) {
8888
if (epsilon === undefined) { epsilon = 0.0001; }
@@ -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)