-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtostring.js
57 lines (46 loc) · 1.25 KB
/
tostring.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict"
var Stringify = function(){this.retString = "", this.localString = ""}
Stringify.prototype.toString = function(num){
var tmpDigit = num
var tmpDigits = num
while(tmpDigits > 0){
tmpDigit = tmpDigits % 10
tmpDigits = Math.floor(tmpDigits / 10)
//console.log(tmpDigits)
if (tmpDigit === 0) {
this.localString += "0"
} else if(tmpDigit === 1) {
this.localString += "1"
} else if(tmpDigit === 2) {
this.localString += "2"
} else if(tmpDigit === 3) {
this.localString += "3"
} else if(tmpDigit === 4) {
this.localString += "4"
} else if(tmpDigit === 5) {
this.localString += "5"
} else if(tmpDigit === 6) {
this.localString += "6"
} else if(tmpDigit === 7) {
this.localString += "7"
} else if(tmpDigit === 8) {
this.localString += "8"
} else if (tmpDigit === 9) {
this.localString += "9"
}
}
}
Stringify.prototype.reverse = function(){
for(var i = this.localString.length; i >= 0; --i) {
//console.log(this.localString.charAt(i))
this.retString += this.localString.charAt(i)
}
}
Stringify.prototype.run = function(num){
this.toString(num)
this.reverse()
return this.retString
}
var n = 8582245346876324
var s = new Stringify().run(n)
console.log("%s:%d::::%s:%s", typeof n, n, typeof s, s )