|
|
@ -5,9 +5,35 @@ |
|
|
|
The objective of this exercise is to merge objects into a new object depending on the values type |
|
|
|
The objective of this exercise is to merge objects into a new object depending on the values type |
|
|
|
|
|
|
|
|
|
|
|
With this create a function called `fusion` that: |
|
|
|
With this create a function called `fusion` that: |
|
|
|
|
|
|
|
|
|
|
|
- If the type is an array you must concat it |
|
|
|
- If the type is an array you must concat it |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
|
|
|
|
fusion([1,2], [3,4]) // -> [1,2,3,4] |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- If it is a string you must concatenate with a space |
|
|
|
- If it is a string you must concatenate with a space |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
|
|
|
|
fusion('Salem', 'alem') // -> 'Salem alem' |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- If it is numbers you must added them |
|
|
|
- If it is numbers you must added them |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
|
|
|
|
fusion(4, 11) // -> 15 |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- In case of type mismatch you must replace it with the value of the second object |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
|
|
|
|
fusion({ a: 'hello', b: [] }, { a: 4 }) |
|
|
|
|
|
|
|
// -> { a: 4, b: [] } |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- If it is an object you must fusion them recursively |
|
|
|
- If it is an object you must fusion them recursively |
|
|
|
- In case of other types you must replace it with the value of the second object |
|
|
|
|
|
|
|
- In case the value don't match you must replace it with the value of the second object |
|
|
|
```js |
|
|
|
|
|
|
|
fusion({ a: 1, b: { c: 'Salem' } }, { a: 10, x: [], b: { c: 'alem' } }) |
|
|
|
|
|
|
|
// -> { a: 11, x: [], b: { c: 'Salem alem' } } |
|
|
|
|
|
|
|
``` |
|
|
|