class BigNumber{
constructor(n){
this.number = this.digitSplitter(n)
}
//adds an integer to the big number
add(x){
x = this.digitSplitter(x)
var j = x.length-1, temp = 0;
var length = x.length >= this.number.length ? x.length : this.number.length
for(var i = length-1; i >= 0;i--,j--){
if(x.length > this.number.length)
temp += x[j]
else if(x.length == this.number.length)
temp += x[j] + this.number[i]
else
temp += this.number[i]
if(temp >= 10){
this.number[i] = temp%10
temp -= temp%10
temp /= 10
}else {
this.number[i] = temp
temp = 0
}
}
return this.number
}
//digit splitter but for Integers larger than 15
digitSplitter(n){
var output;
print("number: "+n)
print("type?: "+ typeof n)
output = n.split('').map(Number)
print(output)
return output;
}
//simply counts digits in a number
digitCount(n){
var count=0
while(n>1){
n/=10;
count++
}
return count
}
}
WHERE THE BAD CODE IS:
constructor(n){
this.number = this.digitSplitter(n)
}
WORKING CODE:
constructor(n){
n = this.digitSplitter(n)
}
NOT WORKING CODE
constructor(n){
n = this.digitSplitter(n)
this.number = n
}
THE OUTPUT: (suppose to count down from 9 to 1, 4 times)
THE INPUT:
any help would be great, I'm thinking it has something todo with pointers and addresses if js even has control on that. I'm not sure what a good work around would be.