JavDev,
var max = "9999" , min = "9";
function difference(max, min) {
max = max.split('')
.reverse();
max.push(0);
min = min.split('')
.reverse();
var len = max.length,
result = [];
for (var i = 0, b = 0, c = 0; i < len; i++) {
b = +max[i] + (+min[i] || 0) + c;
result[i] = b > 9 ? (c = (b/10|0), b % 10) : (c = 0, b)
}
return result.reverse()
.join('')
.replace(/^0+/, '');
}
alert(difference(max,min) )