Javascript Number base(b, c)

Description

Javascript Number base(b, c)


Number.prototype.define("base", function(b, c) {
  var s = "", n = this
  if (b > (c = (c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").split("")).length || b < 2) {
    return ""
  }/*from   w  ww  .j a v a  2  s. c  o  m*/
  while (n) {
    s = c[n % b] + s, n = Math.floor(n / b)
  }
  return s
})



PreviousNext

Related