Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Various ways to swap two variables

  • Loading branch information...
commit b070fc16d245b43aa1dacce166718d156a846cd0 1 parent 5c98500
@isaacs authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 examples/var-swap.js
View
22 examples/var-swap.js
@@ -0,0 +1,22 @@
+
+var foo = 1
+ , bar = 2
+
+function tmpvar () {
+ var _ = foo
+ foo = bar
+ bar = _
+}
+function arrswap () {
+ foo = [bar, bar = foo][0]
+}
+function fnswap () {
+ (function(x,y){foo=x;bar=y})(bar,foo)
+}
+
+exports.compare =
+ { tmpvar: tmpvar
+ , arrswap: arrswap
+ , fnswap: fnswap
+ , "nil function":function () {}
+ }
Please sign in to comment.
Something went wrong with that request. Please try again.