12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- /**
- * Returns a fresh copy of the passed in value
- *
- * @param {unknown} toClone A value to clone
- * @returns {unknown} A clone of the input
- */
- function DeepClone(toClone) {
- return JSON.parse(JSON.stringify(toClone));
- }
- /**
- * Check whether the value at a specific spot in a number is non-zero
- *
- * Similar to the bitwise & operator, checks a "place" in a decimal number
- * to see if it has a non-zero value.
- *
- * @example
- * const test = 107;
- * console.log(DecimalPlaceIsNonZero(test, 1)) // true
- * console.log(DecimalPlaceIsNonZero(test, 2)) // false
- * console.log(DecimalPlaceIsNonZero(test, 3)) // true
- *
- * @param {number} input The number to check
- * @param {number} place The power of 10 to check against
- * @returns {boolean} Whether the value in that number's place is non-zero
- */
- function DecimalPlaceIsNonZero(input, place) {
- return !!GetDecimalInPlace(input, place);
- }
- /**
- * Get the digit in a given place of a decimal number
- *
- * @param {number} input The number to check
- * @param {number} place The power of 10 to check against
- * @returns {number} The number at the specified place in the input
- */
- function GetDecimalInPlace(input, place) {
- return Math.floor((input / (10 ** place)) % 10);
- }
- module.exports = {
- DeepClone: DeepClone,
- DecimalPlaceIsNonZero: DecimalPlaceIsNonZero,
- GetDecimalInPlace: GetDecimalInPlace,
- };
|