text: class StrNum {
  	constructor (str) {
  		this.n = (str == undefined ? "0" : (str == "" ? "0" : "" + str));
  	}
  
  	eq (b) {
  		if (b instanceof StrNum) {
  			return (b.n == this.n ? true : false);
  		} else {
  			return (b == this.toNumberSafe() ? true : false);
  		}
  	}
  
  	gt (b) {
  		if (b instanceof StrNum) {
  			if (this.eq(b)) {
  				return false;
  			} else if (b.n.length > this.n.length) {
  				return false;
  			} else if (b.n.length < this.n.length) {
  				return true;
  			} else {
  				let smaller = false;
  				for (let index = this.n.length - 1; index >= 0; index--) {
  					let numA = Number(this.n.charAt(index));
  					let numB = Number(b.n.charAt(index));
  					if (numB < numA) {
  						return true;
  					}
  				}
  				return false;
  			}
  		} else {
  			if (this.eq(b)) {
  				return false;
  			} else if (Math.floor(Math.log10(b) + 1) > this.n.length) {
  				return false;
  			} else if (Math.floor(Math.log10(b) + 1) < this.n.length) {
  				return true;
  			} else {
  				let smaller = false;
  				let bAsString = "" + b;
  				for (let index = this.n.length - 1; index >= 0; index--) {
  					let numA = Number(this.n.charAt(index));
  					let numB = Number(String(b).charAt(index));
  					if (numB < numA) {
  						return true;
  					}
  				}
  				return false;
  			}
  		}
  	}
  
  	lt (b) {
  		return !this.gt(b) && !this.eq(b);
  	}
  
  	gteq (b) {
  		return this.eq(b) || this.gt(b);
  	}
  
  	lteq (b) {
  		return this.eq(b) || this.lt(b);
  	}
  
  	add (b) {
  		let c = "", overflow = 0, target;
  
  		if (b instanceof StrNum) {
  			c = "";
  			overflow = 0;
  
  			target = (b.n.length > this.n.length ? b : this);
  		} else {
  			c = "";
  			overflow = 0;
  
  			let tempnum = (Math.floor(Math.log10(b) + 1) > this.n.length ? b : this.n);
  			target = {n: "" + tempnum};
  			b = new StrNum(tempnum);
  		}
  
  		for (let index = 0; index < target.n.length; index++) {
  			let numA = (0 <= this.n.length - index - 1 ? Number(this.n.charAt(this.n.length - index - 1)) : 0);
  			let numB = (0 <= b.n.length - index - 1 ? Number(b.n.charAt(b.n.length - index - 1)) : 0);
  
  			let num = numA + numB + overflow;
  
  			if (num >= 10) {
  				c = num % 10 + c;
  				overflow = 1;
  			} else {
  				c = num + c;
  				overflow = 0;
  			}
  		}
  
  		if (overflow) {
  			c = "1" + c;
  			overflow = 0;
  		}
  		this.n = c;
  		return this;
  	}
  
  	sub (b) {
  		return "todo";
  	}
  
  	mult (b) {
  		return "todo";
  	}
  
  	divide (b) {
  		return "todo";
  	}
  
  	shift (b) {
  		if (b instanceof StrNum && b.n.length <= 16) {
  			for (let i = 0; i < b.toNumber(); i++) {
  				this.n += "0";
  			}
  			return this;
  		} else {
  			for (let i = 0; i < b; i++) {
  				this.n += "0";
  			}
  			return this;
  		}
  	}
  
  	randomDigits(b) {
  		let str = "";
  		if (b instanceof StrNum && b.n.length <= 16) {
  			for (let i = 0; i < b.toNumber(); i++) {
  				str += Math.floor(Math.random() * 10);
  			}
  			this.n = str;
  			return this;
  		} else {
  			for (let i = 0; i < b; i++) {
  				this.n += "0";
  			}
  			this.n = str;
  			return this;
  		}
  	}
  
  	toNumberSafe() {
  		return (this.n.length <= 16 ? Number(this.n) : false);
  	}
  
  	toNumber() {
  		return Number(this.n);
  	}
  
  	toExponential() {
  		let str = "";
  		str += this.n.charAt(0);
  		str += ".";
  		if (this.n.length <= 1) {
  			str += "000";
  		} else if (this.n.length <= 2) {
  			str += this.n.charAt(1);
  			str += "00";
  		} else if (this.n.length <= 3) {
  			str += this.n.charAt(1) + this.n.charAt(2);
  			str += "0";
  		} else {
  			str += this.n.charAt(1) + this.n.charAt(2) + this.n.charAt(3);
  		}
  		str += " x 10^";
  		str += this.n.length - 1;
  		return str;
  	}
  }
  
  let a = new StrNum(), b = new StrNum();
  
  function updateInputs() {
  	a = new StrNum($("#input-a").val());
  	b = new StrNum($("#input-b").val());
  }
  
  function validateInputs() {
  	if (a.n.length >= 1 & b.n.length >= 1) return true;
  	else return false;
  }
  
  $(function() {
  	$("#input-a, #input-b").keyup(updateInputs)
  
      $("#btn-add").click(function () {if (validateInputs()) {$("#output").text(a.add(b));}})
      $("#btn-sub").click(function () {if (validateInputs()) {$("#output").text(a.sub(b));}})
  	$("#btn-mul").click(function () {if (validateInputs()) {$("#output").text(a.mult(b));}})
  	$("#btn-div").click(function () {if (validateInputs()) {$("#output").text(a.divide(b));}})
  
      $("#btn-gt").click(function () {if (validateInputs()) {$("#output").text(a.gt(b));}})
      $("#btn-lt").click(function () {if (validateInputs()) {$("#output").text(a.lt(b));}})
      $("#btn-eq").click(function () {if (validateInputs()) {$("#output").text(a.eq(b));}})
  
      // time();
  });
  
  function time(numberOfOperations = 100000, digits = 100) {
  	let res = [];
      let timeStart = Date.now();
      for (let i = 0; i < numberOfOperations; i++) {
      	let a = new StrNum();
      	let b = new StrNum();
      	a.randomDigits(digits);
      	b.randomDigits(digits);
      	let r = a.add(b);
      	res.push(r);
      }
      let timeEnd = Date.now();
      console.log(res);
      console.log(timeEnd - timeStart);
  }