common.js 1007 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Returns a fresh copy of the passed in value
  3. *
  4. * @param {unknown} toClone A value to clone
  5. * @returns {unknown} A clone of the input
  6. */
  7. function DeepClone(toClone) {
  8. return JSON.parse(JSON.stringify(toClone));
  9. }
  10. /**
  11. * Check whether the value at a specific spot in a number is non-zero
  12. *
  13. * Similar to the bitwise & operator, checks a "place" in a decimal number
  14. * to see if it has a non-zero value.
  15. *
  16. * @example
  17. * const test = 107;
  18. * console.log(DecimalPlaceIsNonZero(test, 1)) // true
  19. * console.log(DecimalPlaceIsNonZero(test, 2)) // false
  20. * console.log(DecimalPlaceIsNonZero(test, 3)) // true
  21. *
  22. * @param {number} input The number to check
  23. * @param {number} place The power of 10 to check against
  24. * @returns {boolean} Whether the value in that number's place is non-zero
  25. */
  26. function DecimalPlaceIsNonZero(input, place) {
  27. return !!Math.floor((input / (10 ** place)) % 10);
  28. }
  29. module.exports = {
  30. DeepClone: DeepClone,
  31. DecimalPlaceIsNonZero: DecimalPlaceIsNonZero,
  32. };