Created
May 18, 2017 05:54
-
-
Save qvil/0643ad3f01be2d6a7f5c90997c6c3d91 to your computer and use it in GitHub Desktop.
Javascript file about mathmatics(Not Using ES6 for compatability with less than IE8. But want to using ES6 whenever..(If i resolve compatability problem using polyfill))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var math = { | |
/** | |
* Return divided values | |
* @date 2017.05.18 | |
* @author tshyeon | |
* @param {number} dividend | |
* @param {number} divisor | |
* @return {number} result | |
* @example math.divider(150, 10) // {quotient: 15, remainder: 0, value: 15.0} | |
*/ | |
divider: function(dividend, divisor) { | |
var defaultValue = 0; | |
var dividedType = typeof dividend; | |
var divisorType = typeof divisor; | |
// Arguments Check | |
if ( dividedType === "undefined" ) { | |
console.error("[TS_Error] math.dividend : Invalid dividedType is " + dividedType); | |
return defaultValue; | |
} | |
else if ( isNaN(dividend) ) { | |
console.error("[TS_Error] math.dividend : Invalid NaN dividend"); | |
return defaultValue; | |
} | |
if ( divisor === 0 ) { | |
console.error("[TS_Error] math.divisor : Invalid divisor is " + divisor); | |
return defaultValue; | |
} | |
// Type Check | |
if ( dividedType !== "number" ) { | |
console.error("[TS_Error] math.divider : Invalid divident type '" + dividedType + "'"); | |
return defaultValue; | |
} | |
if ( divisorType !== "number" ) { | |
console.error("[TS_Error] math.divider : Invalid divisor type '" + divisorType + "'"); | |
return defaultValue; | |
} | |
// Progress | |
return dividend / divisor; | |
// Deprecated.. | |
/** | |
* @typedef {Object} result - Result Object | |
* @property {number} quotient | |
* @property {number} remainder | |
* @property {string} value - String value of combined quotient and remainder | |
*/ | |
// var quotient; | |
// var remainder; | |
// var result = {}; | |
// quotient = dividend / divisor; | |
// remainder = dividend % divisor; | |
// if (remainder === 0) remainder = 0; // for check -0 | |
// result.quotient = quotient; | |
// result.remainder = remainder; | |
// if ( quotient.toString().indexOf('.') === -1 ) { | |
// result.value = quotient; | |
// } | |
// else if ( quotient === 0 && remainder === 0 ) { | |
// result.value = 0; | |
// } | |
// else { | |
// result.value = quotient + '.' + remainder; | |
// } | |
// return result; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment