Browse Source

clarify fusion subject with examples

content-update
Clément 4 years ago committed by GitHub
parent
commit
aec49bda47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      subjects/fusion/README.md

30
subjects/fusion/README.md

@ -5,9 +5,35 @@
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:
- 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
```js
fusion('Salem', 'alem') // -> 'Salem alem'
```
- 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
- 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' } }
```

Loading…
Cancel
Save