Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,23 @@
---
title: Copy sign to number
type: snippet
tags: [math]
cover: keyboard-tea
dateModified: 2020-10-07T23:52:57+03:00
---
Returns the absolute value of the first number, but the sign of the second.
- Use `Math.sign()` to check if the two numbers have the same sign.
- Return `x` if they do, `-x` otherwise.
```js
const copySign = (x, y) => Math.sign(x) === Math.sign(y) ? x : -x;
```
```js
copySign(2, 3); // 2
copySign(2, -3); // -2
copySign(-2, 3); // 2
copySign(-2, -3); // -2
```