[JS] Add duplicate function with ES6 Syntax (#219)
This commit is contained in:
parent
be004582fb
commit
344c0bc5bf
|
|
@ -710,6 +710,14 @@ function duplicate(arr) {
|
|||
duplicate([1, 2, 3, 4, 5]); // [1,2,3,4,5,1,2,3,4,5]
|
||||
```
|
||||
|
||||
Or with ES6:
|
||||
|
||||
```js
|
||||
const duplicate = (arr) => [...arr, ...arr];
|
||||
|
||||
duplicate([1, 2, 3, 4, 5]); // [1,2,3,4,5,1,2,3,4,5]
|
||||
```
|
||||
|
||||
[[↑] Back to top](#js-questions)
|
||||
|
||||
### Why is it called a Ternary expression, what does the word "Ternary" indicate?
|
||||
|
|
|
|||
Loading…
Reference in New Issue