code: function (value, min, max) {
              var interval;
              if (min > max) {
                  max = min + max;
                  min = max - min;
                  max = max - min;
              }
              interval = max - min;
              return min + ((value % interval) + interval) % interval;
          }
docs: Wraps a number inside a given range with modulo operation.