|
|
@ -4,36 +4,37 @@ |
|
|
|
|
|
|
|
|
|
|
|
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 concatenate it |
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
```js |
|
|
|
fusion([1, 2], [3, 4]) // -> [1,2,3,4] |
|
|
|
fusion({ arr: [1, "2"] }, { arr: [2] }); // -> { arr: [ 1, '2', 2 ] } |
|
|
|
|
|
|
|
fusion({ arr: [], arr1: [5] },{ arr: [10, 3], arr1: [15, 3], arr2: ["7", "1"] }); // ->{ arr: [ 10, 3 ], arr1: [ 5, 15, 3 ], arr2: [ '7', '1' ] } |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- If it is a string you must concatenate with a space |
|
|
|
- If it is a string you must concatenate it with a space |
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
```js |
|
|
|
fusion('Salem', 'alem') // -> 'Salem alem' |
|
|
|
fusion({ str: "salem" }, { str: "alem" }); // -> { str: 'salem alem' } |
|
|
|
|
|
|
|
fusion({ str: "salem" }, { str: "" }); // -> { str: 'salem ' } |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- If it is numbers you must added them |
|
|
|
- If they are numbers, you must add them |
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
```js |
|
|
|
fusion(4, 11) // -> 15 |
|
|
|
fusion({ a: 10, b: 8, c: 1 }, { a: 10, b: 2 }); // -> { a: 20, b: 10, c: 1 } |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- In case of type mismatch you must replace it with the value of the second object |
|
|
|
- If it is an object, you must join them recursively |
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
```js |
|
|
|
fusion({ a: 'hello', b: [] }, { a: 4 }) |
|
|
|
fusion({ a: 1, b: { c: "Salem" } }, { a: 10, x: [], b: { c: "alem" } }); // -> { a: 11, x: [], b: { c: 'Salem alem' } } |
|
|
|
// -> { a: 4, b: [] } |
|
|
|
fusion( { a: { b: [3, 2], c: { d: 8 } } },{ a: { b: [0, 3, 1], c: { d: 3 } } }); // -> { a: { b: [ 3, 2, 0, 3, 1 ], c: { d: 11 } } } |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- If it is an object you must fusion them recursively |
|
|
|
- In case of type mismatch you must replace it with the value of the second object |
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
```js |
|
|
|
fusion({ a: 1, b: { c: 'Salem' } }, { a: 10, x: [], b: { c: 'alem' } }) |
|
|
|
fusion({ a: "hello", b: [] }, { a: 4 }); // -> { a: 4, b: [] } |
|
|
|
// -> { a: 11, x: [], b: { c: 'Salem alem' } } |
|
|
|
|
|
|
|
``` |
|
|
|
``` |
|
|
|