Skip to content

Instantly share code, notes, and snippets.

@mr21
Created August 7, 2018 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr21/097fa551e26b41f9f2539ed46215091d to your computer and use it in GitHub Desktop.
Save mr21/097fa551e26b41f9f2539ed46215091d to your computer and use it in GitHub Desktop.
Math.min/max/round/... check for NaN
( function() {
const _Math = {
min: Math.min,
max: Math.max,
abs: Math.abs,
ceil: Math.ceil,
floor: Math.floor,
round: Math.round,
};
Math.min = mathCall.bind( null, "min" );
Math.max = mathCall.bind( null, "max" );
Math.abs = mathCall.bind( null, "abs" );
Math.ceil = mathCall.bind( null, "ceil" );
Math.floor = mathCall.bind( null, "floor" );
Math.round = mathCall.bind( null, "round" );
function mathCall( fn ) {
const arr = Array.from( arguments ),
_ = arr.shift(),
res = _Math[ fn ].apply( Math, arr );
if ( isNaN( res ) ) {
console.warn( `NaN detected on Math.${ fn }( ${ arr } )` );
}
return res;
};
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment