So you can swap array elements using ES6 with the following notation:
let a = [1, 2, 3, 4];
[a[0], a[1]] = [a[1], a[0]];
console.log(a); // [2, 1, 3, 4];
But I'm curious to know the time/space complexity of this.
If it's just syntactic sugar for:
var temp = a[0];
a[0] = a[1];
a[1] = temp;
Then I'd imagine it's O(1) for both time and space.
I suppose even if we are creating a whole new array to make the destructuring and then assignment, would still all be constant since we're only ever swapping a couple of elements. Does this sound right?