mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-12-08 19:06:00 +00:00
9 lines
190 B
JavaScript
9 lines
190 B
JavaScript
/**
|
|
* Switch the sign of the number using "Twos Complement" approach.
|
|
* @param {number} number
|
|
* @return {number}
|
|
*/
|
|
export default function switchSign(number) {
|
|
return ~number + 1;
|
|
}
|