Travis build: 765 [ci skip]
This commit is contained in:
30
README.md
30
README.md
@ -272,6 +272,7 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
|
|
||||||
|
* [`join`](#join)
|
||||||
* [`sortedIndex`](#sortedindex)
|
* [`sortedIndex`](#sortedindex)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
@ -4589,6 +4590,35 @@ yesNo('Foo', true); // true
|
|||||||
---
|
---
|
||||||
## _Uncategorized_
|
## _Uncategorized_
|
||||||
|
|
||||||
|
### join
|
||||||
|
|
||||||
|
Joins all elements of an array into a string and returns this string. Uses a separator and an end separator.
|
||||||
|
|
||||||
|
Use `Array.reduce()` to combine elements into a string.
|
||||||
|
Omit the second argument, `separator`, to use a default separator of `','`.
|
||||||
|
Omit the third argument, `end`, to use the same value as `separator` by default.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const join = (arr, separator = ',', end = separator) =>
|
||||||
|
arr.reduce(
|
||||||
|
(acc, val, i) =>
|
||||||
|
i == arr.length - 2
|
||||||
|
? acc + val + end
|
||||||
|
: i == arr.length - 1 ? acc + val : acc + val + separator,
|
||||||
|
''
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
join(); // ''
|
||||||
|
join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'); //"pen,pineapple,apple&pen"
|
||||||
|
join(['pen', 'pineapple', 'apple', 'pen'], ','); //"pen,pineapple,apple,pen"
|
||||||
|
join(['pen', 'pineapple', 'apple', 'pen']); //"pen,pineapple,apple,pen"
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### sortedIndex
|
### sortedIndex
|
||||||
|
|
||||||
Returns the lowest index at which value should be inserted into array in order to maintain its sort order.
|
Returns the lowest index at which value should be inserted into array in order to maintain its sort order.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -15,7 +15,6 @@ const join = (arr, separator = ',', end = separator) =>
|
|||||||
: i == arr.length - 1 ? acc + val : acc + val + separator,
|
: i == arr.length - 1 ? acc + val : acc + val + separator,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -81,6 +81,7 @@ isPromiseLike:utility
|
|||||||
isString:utility
|
isString:utility
|
||||||
isSymbol:utility
|
isSymbol:utility
|
||||||
isValidJSON:utility
|
isValidJSON:utility
|
||||||
|
join:uncategorized
|
||||||
JSONToDate:date
|
JSONToDate:date
|
||||||
JSONToFile:node
|
JSONToFile:node
|
||||||
last:array
|
last:array
|
||||||
|
|||||||
Reference in New Issue
Block a user