Skip to content

Instantly share code, notes, and snippets.

@tsvetomir
Created July 18, 2012 08:16
Show Gist options
  • Save tsvetomir/3134997 to your computer and use it in GitHub Desktop.
Save tsvetomir/3134997 to your computer and use it in GitHub Desktop.
My attempt at solving https://gist.github.com/3134886
function Point(a, b) {
if (arguments.length === 1) {
this.x = Math.round(a / 1000);
this.y = a - this.x * 1000;
} else {
this.x = a;
this.y = b;
}
}
Point.prototype.valueOf = function () {
return this.x * 1000 + this.y;
}
Point.prototype.toString = function () {
return "{" + this.x + "," + this.y + "}";
}
new Point(new Point(10, 20) + new Point(30, 50)).toString() // === "{40,70}"
@padolsey
Copy link

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment