JavaScript实现切换数字的符号switchSign算法(附完整源码)
- switchSign.js完整源代码
switchSign.js完整源代码
/**
* Switch the sign of the number using "Twos Complement" approach.
* @param {number} number
* @return {number}
*/
export default function switchSign(number) {
return ~number + 1;
}
该博文为原创文章,未经博主同意不得转载,如同意转载请注明博文出处