var isEven = function(n) { return !(n&1) // & 按位与 } console.log(1, isEven(1)) console.log(25, isEven(25)) console.log(138, isEven(138)) var isEven = function(n) { return !!n.toString().match(/[02468]$/) } console.log(1, isEven(1)) console.log(25, isEven(25)) console.log(138, isEven(138)) var isEven = function(n) { return !(n % 2) } console.log(1, isEven(1)) console.log(25, isEven(25)) console.log(138, isEven(138))
时间: 2024-11-03 22:50:27