Nodejs Number Calculate snap(resolution)

Here you can find the source of snap(resolution)

Method Source Code

Number.prototype.snap = function(resolution) {
  return Math.floor(this / resolution) * resolution;
};

Related

  1. setInRangesetInRange(lower, upper)
    Number.prototype.setInRange = function setInRange(lower, upper){
      if (typeof lower === "undefined" || lower === null){
        lower = this;
      if (typeof upper === "undefined" || upper === null){
        upper = this;
      lower = parseFloat(lower) || 0;
      upper = parseFloat(upper) || 0;
    ...
    
  2. sigFig(precision)
    'use strict'
    Number.prototype.sigFig = function(precision){
        if( !precision ) precision = 2;
        var d = Math.pow(10, precision);
        return ( parseInt( this.valueOf() * d) / d ).toFixed(precision);
    };
    
  3. simEq(number, digits)
    DEFAULT_DIGIT = 5;
    Number.prototype.simEq = function(number, digits) {
      digits = digits == undefined ? DEFAULT_DIGIT : digits;
      var n1 = this.toFixed(digits);
      var n2 = number.toFixed(digits);
      if (n1 == -0)
        n1 = 0;
      if (n2 == -0)
        n2 = 0;
    ...
    
  4. sin()
    Number.prototype.sin = function() {
        return Math.sin(this);
    
  5. smallerThan(num)
    Number.prototype.smallerThan = function(num) {
        return this < num;
    
  6. sqrt()
    Number.prototype.sqrt = function() {
      return Math.sqrt(this);
    };
    
  7. square()
    var expect = chai.expect;
    Number.prototype.square = function () {
        "use strict";
        return this * this;
    };
    
  8. square()
    Number.prototype.square = function() {
      return this * this;
    };
    
  9. step(to, add_remove_step)
    Number.prototype.step = function (to, add_remove_step) {
      var from = this.valueOf();
      var ch = add_remove_step.match(/[\+,\-]/g)[0];
      var i = from;
      var arr = [];
      if (ch === '+') {
        while (i <= to) {
          arr.push(i);
          i = i + parseInt(add_remove_step);
    ...