Write a function swapPair(pair) that swaps two numbers without a third variable.
A function cannot change the variables of the code that called it, so the two numbers come in an array: pair is [a, b].
pair itself so that it becomes [b, a], then return that same array, not a new one.a and b are integers from -1000000000000 to 1000000000000. They can be negative, zero or equal.let, const or var, do not add a second parameter, and do not write another function in it (its parameters would be variables too).pair: do not add items or properties to the array or to the function, and do not create a global variable (temp = pair[0] without let creates one).swapPair([1, 2])Returns [ 2, 1 ]
swapPair([-5, 0])Returns [ 0, -5 ]
Asked at ServiceNow · Source
swapPair([ 1, 2 ])[ 2, 1 ]Hidden tests run on Submit.