Swapping four variables without temporary variable | Javascript program to swap 4 variables without using temporary variable . ; swapping a and b variables ; swapping b and c variables ; swapping c and d variables ; initialising variables ; Function call
function swap ( a , b , c , d ) { a = a + b ; b = a - b ; a = a - b ; b = b + c ; c = b - c ; b = b - c ; c = c + d ; d = c - d ; c = c - d ; document . write ( " " + " " ) ; document . write ( " " + a + " " ) ; document . write ( " " + b + " " ) ; document . write ( " " + c + " " ) ; document . write ( " " + d ) ; } let a = 1 ; let b = 2 ; let c = 3 ; let d = 4 ; document . write ( " " + " " ) ; document . write ( " " + a + " " ) ; document . write ( " " + b + " " ) ; document . write ( " " + c + " " ) ; document . write ( " " + d + " " ) ; document . write ( " " + " " ) ; swap ( a , b , c , d ) ;