Rename js snippets

This commit is contained in:
Angelos Chalaris
2023-05-19 20:23:47 +03:00
parent 82a614e42e
commit 9d032ce05e
305 changed files with 70 additions and 70 deletions

View File

@ -0,0 +1,23 @@
---
title: Logical complement
type: snippet
language: javascript
tags: [function,logic]
cover: flower-portrait-10
dateModified: 2020-09-15T16:28:04+03:00
---
Returns a function that is the logical complement of the given function, `fn`.
- Use the logical not (`!`) operator on the result of calling `fn` with any supplied `args`.
```js
const complement = fn => (...args) => !fn(...args);
```
```js
const isEven = num => num % 2 === 0;
const isOdd = complement(isEven);
isOdd(2); // false
isOdd(3); // true
```