Skip to content

Instantly share code, notes, and snippets.

@javascripter
Created November 3, 2009 14:25
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 javascripter/225078 to your computer and use it in GitHub Desktop.
Save javascripter/225078 to your computer and use it in GitHub Desktop.
function abs(n) {
return n >= 0 ? 0+n : -n;
}
function run_tests() {
console.assert(abs(0) == 0, "abs(0) == 0");
console.assert(abs(1) == 1, "abs(1) == 1");
console.assert(abs(-1) == 1, "abs(-1) == 1");
console.assert(1/0 == 1/abs(-0), "1/0 == 1/abs(-0)");
console.assert(1/-0 != 1/abs(-0), "1/-0 != 1/abs(-0)");
}
run_tests();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment