javascript - Addition and subtraction within bounds -
how write following in javascript:
row-=21; if (row < 1) { row = 1; }
you can this:
row = math.max( row-21, 1);
edit:
if want able set minimum and/or maximum range, prototype own function number.
number.prototype.adjust = function( adj, min, max ) { if( isnan( min ) ) min = -infinity; if( isnan( max ) ) max = infinity; var res = + ~~adj; return res < min ? min : res > max ? max : res; };
then can use this:
row = row.adjust( -21, 1, 50 ); /* adjustment, min, max */
- 1st argument adjustment
- 2nd argument minimum range (pass null no min)
- 3rd argument maximum range (pass null or leave blank no max)
Comments
Post a Comment