Open zlx362211854 opened 4 years ago
var a = 2; var b = 5; // 如何不使用第三个变量,使两个数反转,即a = 5, b = 2
// 方法1: var a = 2; var b = 5; [a,b] = [b,a] // 方法2(只适用a,b都是数字的情况): var a = 2; var b = 5; a = b - a // 5 - 2 = 3 b = b - a // 5 - 3 = 2 a = a + b // 3 + 2 = 5