DEV Community

Discussion on: How can you swap two variables without using a third?

Collapse
 
codevault profile image
Sergiu Mureşan • Edited

I think it doesn't like the double assignment on same expression. In JS you can do:

[a, b] = [b, a];

or

b = [a, a = b][0];

although less readable.

Thread Thread
 
theoutlander profile image
Nick Karnik

[] allocates new space I think so this solution won't be in constant space.