[JS] Add duplicate function with ES6 Syntax (#219)

This commit is contained in:
Filip Barakovski 2019-10-26 19:15:12 +02:00 committed by Yangshun Tay
parent be004582fb
commit 344c0bc5bf
1 changed files with 8 additions and 0 deletions

View File

@ -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?