Value Reversal

EasyAcc. 92.1%
+20 XP 8

Memory Exchange

Two critical data buffers have been swapped by a solar flare. You must restore them to their correct positions.

To swap two variables without losing data, you need a third temporary variable to hold one value while the other is moved.

  1. Declare a temporary variable named temp.
  2. Perform the swap so that a gets the value of b, and b gets the original value of a.
  3. Return the results as an array: [a, b].

01EXAMPLE 1

Inputa = 5, b = 10
Output[10, 5]

Explanation: After the swap, a is 10 and b is 5.

Constraints

  • Use a temporary variable if possible.
  • Return the result as [a, b].
FundamentalsVariablesLogic
JavaScript
Loading...
9 Hidden

Input Arguments

a5
b10

Expected Output

[10,5]

Click RUN to test your solution