Created
July 18, 2012 08:16
-
-
Save tsvetomir/3134997 to your computer and use it in GitHub Desktop.
My attempt at solving https://gist.github.com/3134886
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!