Skip to content

Instantly share code, notes, and snippets.

@lukeschunk
Last active August 5, 2016 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeschunk/56e8c44739d4c90bc513 to your computer and use it in GitHub Desktop.
Save lukeschunk/56e8c44739d4c90bc513 to your computer and use it in GitHub Desktop.
Difficult JS Interview Question
(function () {
function Arithmetic(number) {
this.value = number;
};
Arithmetic.val = function () {
return this.value;
};
Arithmetic.add = function (number) {
this.value += number;
};
Arithmetic.subtract = function (number) {
console.log("this is this.value", this.value);
this.value = this.value - number;
};
window.Arithmetic = function (number) {
return new Arithmetic(number);
};
})();
var workingNumber = Arithmetic(10).subtract(5).add(7).add(1).val(); // Should return 13
var otherWorkingNumber = Arithmetic(100).add(1).subtract(99).val(); // Should return 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment