Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Last active August 29, 2015 13:57
Show Gist options
  • Save animatedlew/9491796 to your computer and use it in GitHub Desktop.
Save animatedlew/9491796 to your computer and use it in GitHub Desktop.
function add(a, b) {
if (a >= 0) while(a--) b++;
else while(a++) b--;
return b;
}
console.log(add( 5, 2)); // 7
console.log(add(-5, 2)); // -3
console.log(add( 5,-2)); // 3
console.log(add(-5,-2)); // -7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment