Value Exchange

EasyAcc. 92.1%
+20 XP 8

Swapping Places

Sometimes we need to exchange the values of two containers, like swapping duty shifts of two workers. To do this without losing data, we use a third empty variable as temporary holding.

The Assignment

Your function gets two variables, a and b.

  1. Declare a temporary variable named temp.
  2. Use it to safely swap the values so that a takes b's value, and b takes a's old value.
  3. Return them 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...
5 Hidden

Input Arguments

a5
b10

Expected Output

[10,5]

Click RUN to test your solution