Travis build: 920
This commit is contained in:
28
README.md
28
README.md
@ -291,6 +291,7 @@
|
|||||||
* [`geometricProgression`](#geometricprogression)
|
* [`geometricProgression`](#geometricprogression)
|
||||||
* [`maxN`](#maxn)
|
* [`maxN`](#maxn)
|
||||||
* [`minN`](#minn)
|
* [`minN`](#minn)
|
||||||
|
* [`pluralize`](#pluralize)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@ -5164,6 +5165,33 @@ minN([1, 2, 3], 4); // [1,2,3]
|
|||||||
<br>[⬆ back to top](#table-of-contents)
|
<br>[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
# pluralize
|
||||||
|
|
||||||
|
If `num` is greater than `1` returns the plural form of the given string, else return the singular form.
|
||||||
|
|
||||||
|
Check if `num` is positive. Throw an appropriate `Error` if not, return the appropriate string otherwise.
|
||||||
|
Omit the third argument, `items`, to use a default plural form same as `item` suffixed with a single `'s'`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const pluralize = (num, item, items = item + 's') =>
|
||||||
|
num <= 0
|
||||||
|
? (() => {
|
||||||
|
throw new Error(`'num' should be >= 1. Value povided was ${num}.`);
|
||||||
|
})()
|
||||||
|
: num === 1 ? item : items;
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
pluralize(1, 'apple', 'apples'); // 'apple'
|
||||||
|
pluralize(3, 'apple', 'apples'); // 'apples'
|
||||||
|
pluralize(2, 'apple'); // 'apples'
|
||||||
|
pluralize(0, 'apple', 'apples'); // Gives error
|
||||||
|
pluralize(-3, 'apple', 'apples'); // Gives error
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
## Collaborators
|
## Collaborators
|
||||||
|
|
||||||
| [<img src="https://github.com/Chalarangelo.png" width="100px;"/>](https://github.com/Chalarangelo)<br/> [<sub>Angelos Chalaris</sub>](https://github.com/Chalarangelo) | [<img src="https://github.com/Pl4gue.png" width="100px;"/>](https://github.com/Pl4gue)<br/> [<sub>David Wu</sub>](https://github.com/Pl4gue) | [<img src="https://github.com/fejes713.png" width="100px;"/>](https://github.com/fejes713)<br/> [<sub>Stefan Feješ</sub>](https://github.com/fejes713) | [<img src="https://github.com/kingdavidmartins.png" width="100px;"/>](https://github.com/kingdavidmartins)<br/> [<sub>King David Martins</sub>](https://github.com/iamsoorena) | [<img src="https://github.com/iamsoorena.png" width="100px;"/>](https://github.com/iamsoorena)<br/> [<sub>Soorena Soleimani</sub>](https://github.com/iamsoorena) |
|
| [<img src="https://github.com/Chalarangelo.png" width="100px;"/>](https://github.com/Chalarangelo)<br/> [<sub>Angelos Chalaris</sub>](https://github.com/Chalarangelo) | [<img src="https://github.com/Pl4gue.png" width="100px;"/>](https://github.com/Pl4gue)<br/> [<sub>David Wu</sub>](https://github.com/Pl4gue) | [<img src="https://github.com/fejes713.png" width="100px;"/>](https://github.com/fejes713)<br/> [<sub>Stefan Feješ</sub>](https://github.com/fejes713) | [<img src="https://github.com/kingdavidmartins.png" width="100px;"/>](https://github.com/kingdavidmartins)<br/> [<sub>King David Martins</sub>](https://github.com/iamsoorena) | [<img src="https://github.com/iamsoorena.png" width="100px;"/>](https://github.com/iamsoorena)<br/> [<sub>Soorena Soleimani</sub>](https://github.com/iamsoorena) |
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -5,15 +5,19 @@ If `num` is greater than `1` returns the plural form of the given string, else r
|
|||||||
Check if `num` is positive. Throw an appropriate `Error` if not, return the appropriate string otherwise.
|
Check if `num` is positive. Throw an appropriate `Error` if not, return the appropriate string otherwise.
|
||||||
Omit the third argument, `items`, to use a default plural form same as `item` suffixed with a single `'s'`.
|
Omit the third argument, `items`, to use a default plural form same as `item` suffixed with a single `'s'`.
|
||||||
|
|
||||||
``` js
|
```js
|
||||||
const pluralize = (num, item, items = item+'s') =>
|
const pluralize = (num, item, items = item + 's') =>
|
||||||
num <= 0 ? (() => {throw new Error(`'num' should be >= 1. Value povided was ${num}.`)})() : num === 1 ? item : items;
|
num <= 0
|
||||||
|
? (() => {
|
||||||
|
throw new Error(`'num' should be >= 1. Value povided was ${num}.`);
|
||||||
|
})()
|
||||||
|
: num === 1 ? item : items;
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
pluralize(1,'apple','apples'); // 'apple'
|
pluralize(1, 'apple', 'apples'); // 'apple'
|
||||||
pluralize(3,'apple','apples'); // 'apples'
|
pluralize(3, 'apple', 'apples'); // 'apples'
|
||||||
pluralize(2,'apple'); // 'apples'
|
pluralize(2, 'apple'); // 'apples'
|
||||||
pluralize(0,'apple','apples'); // Gives error
|
pluralize(0, 'apple', 'apples'); // Gives error
|
||||||
pluralize(-3,'apple','apples'); // Gives error
|
pluralize(-3, 'apple', 'apples'); // Gives error
|
||||||
```
|
```
|
||||||
|
|||||||
@ -111,6 +111,7 @@ palindrome:string
|
|||||||
percentile:math
|
percentile:math
|
||||||
pick:array
|
pick:array
|
||||||
pipeFunctions:adapter
|
pipeFunctions:adapter
|
||||||
|
pluralize:uncategorized
|
||||||
powerset:math
|
powerset:math
|
||||||
prettyBytes:utility
|
prettyBytes:utility
|
||||||
primes:math
|
primes:math
|
||||||
|
|||||||
Reference in New Issue
Block a user