Simplify isEven function
This commit is contained in:
@ -195,11 +195,11 @@ const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|||||||
|
|
||||||
### Even or odd number
|
### Even or odd number
|
||||||
|
|
||||||
Use `Math.abs()` to extend logic to negative numbers, check using the modulo (`%`) operator.
|
Checks whether number is odd or even using the modulo (`%`) operator.
|
||||||
Return `true` if the number is even, `false` if the number is odd.
|
Returns `true` if the number is even, `false` if the number is odd.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isEven = num => Math.abs(num) % 2 === 0;
|
const isEven = num => num % 2 === 0;
|
||||||
// isEven(3) -> false
|
// isEven(3) -> false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
### Even or odd number
|
### Even or odd number
|
||||||
|
|
||||||
Use `Math.abs()` to extend logic to negative numbers, check using the modulo (`%`) operator.
|
Checks whether number is odd or even using the modulo (`%`) operator.
|
||||||
Return `true` if the number is even, `false` if the number is odd.
|
Returns `true` if the number is even, `false` if the number is odd.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isEven = num => Math.abs(num) % 2 === 0;
|
const isEven = num => num % 2 === 0;
|
||||||
// isEven(3) -> false
|
// isEven(3) -> false
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user