Explorer
Node.js

Write a function `swap(a, b)` that returns `[b, a]` using destructuring assignment.

Problem Statement

Write a function `swap(a, b)` that returns `[b, a]` using destructuring assignment.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Destructuring can be used to swap values. šŸ’” Hint 2: [a, b] = [b, a] swaps the values. šŸ’” Hint 3: return [b, a]; āœ… Solution: ```javascript function swap(a, b) { return [b, a]; } ```

Swap Variables Without Temp

Easy
Write a function `swap(a, b)` that returns `[b, a]` using destructuring assignment.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
[2,1]