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.
- Declare a temporary variable named
temp. - Perform the swap so that
agets the value ofb, andbgets the original value ofa. - Return the results as an array:
[a, b].
01EXAMPLE 1
Input
a = 5, b = 10Output
[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
JavaScriptSystem handles I/O — write your function only
Loading...
9 Hidden
Input Arguments
a5
b10
Expected Output
[10,5]
Click RUN to test your solution