Build README

This commit is contained in:
Angelos Chalaris
2017-12-13 13:48:12 +02:00
parent fb59292c76
commit 3bfba2bb69

View File

@ -58,6 +58,7 @@
* [Sum of array of numbers](#sum-of-array-of-numbers) * [Sum of array of numbers](#sum-of-array-of-numbers)
* [Swap values of two variables](#swap-values-of-two-variables) * [Swap values of two variables](#swap-values-of-two-variables)
* [Tail of list](#tail-of-list) * [Tail of list](#tail-of-list)
* [Truncate_a_string](#truncate_a_string)
* [Unique values of array](#unique-values-of-array) * [Unique values of array](#unique-values-of-array)
* [URL parameters](#url-parameters) * [URL parameters](#url-parameters)
* [UUID generator](#uuid-generator) * [UUID generator](#uuid-generator)
@ -591,6 +592,17 @@ const tail = arr => arr.length > 1 ? arr.slice(1) : arr;
// tail([1]) -> [1] // tail([1]) -> [1]
``` ```
### Truncate a String
Determine if the string's `length` is greater than `num`.
Return the string truncated to the desired length, with `...` appended to the end or the original string.
```
const truncate = (str, num) =>
str.length > num ? str.slice(0, num > 3 ? num-3 : num) + '...' : str;
// truncate('boomerang', 7) -> 'boom...'
```
### Unique values of array ### Unique values of array
Use ES6 `Set` and the `...rest` operator to discard all duplicated values. Use ES6 `Set` and the `...rest` operator to discard all duplicated values.