2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Combine Two Arrays Using the concat Method
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Combine Two Arrays Using the concat Method
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
- The concat method is used to join two or more arrays or strings.
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
### Hint 2
|
2018-10-12 15:37:13 -04:00
|
|
|
- This method does not mutate the existing arrays, but returns a new array.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
```javascript
|
|
|
|
function nonMutatingConcat(original, attach) {
|
|
|
|
// Add your code below this line
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
return original.concat(attach);
|
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
// Add your code above this line
|
|
|
|
}
|
|
|
|
var first = [1, 2, 3];
|
|
|
|
var second = [4, 5];
|
|
|
|
nonMutatingConcat(first, second);
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|