Nest all content into snippets

This commit is contained in:
Angelos Chalaris
2023-05-07 16:07:29 +03:00
parent 2ecadbada9
commit 6a45d2ec07
1240 changed files with 0 additions and 0 deletions

24
snippets/js/s/either.md Normal file
View File

@ -0,0 +1,24 @@
---
title: Logical or for functions
type: snippet
language: javascript
tags: [function,logic]
cover: man-red-sunset
dateModified: 2020-10-19T18:51:03+03:00
---
Checks if at least one function returns `true` for a given set of arguments.
- Use the logical or (`||`) operator on the result of calling the two functions with the supplied `args`.
```js
const either = (f, g) => (...args) => f(...args) || g(...args);
```
```js
const isEven = num => num % 2 === 0;
const isPositive = num => num > 0;
const isPositiveOrEven = either(isPositive, isEven);
isPositiveOrEven(4); // true
isPositiveOrEven(3); // true
```