Browse Source

solving some issues on fusion and debounce exercises

pull/938/head
miguel 2 years ago
parent
commit
9a22c4b8b0
  1. 2
      js/tests/debounce_test.js
  2. 18
      js/tests/fusion_test.js
  3. 27
      subjects/fusion/README.md

2
js/tests/debounce_test.js

@ -67,7 +67,7 @@ t(async ({ eq }) =>
run(opDebounce(add, 200, { leading: true }), { delay: 70, count: 3 }),
run(opDebounce(add, 100, { leading: true }), { delay: 140, count: 3 }),
]),
[1, 2]
[1, 3]
)
)

18
js/tests/fusion_test.js

@ -65,22 +65,4 @@ t(({ eq }) =>
)
)
t(({ eq }) =>
// object mutability
eq(
fusion(Object.freeze({ a: { b: 1 } }), Object.freeze({ a: { b: 2 } })).a.b,
3
)
)
// other types
t(({ eq }) => eq(fusion({ reg: /\w/ }, { reg: /\S/ }).reg, /\S/))
t(({ eq }) => {
const set = new Set([1, 2, 3])
return eq(fusion({ a: 1, set: new Set([4, 5, 6]) }, { a: 1, set }), {
a: 2,
set,
})
})
Object.freeze(tests)

27
subjects/fusion/README.md

@ -4,36 +4,37 @@
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
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
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
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
fusion({ a: 'hello', b: [] }, { a: 4 })
// -> { a: 4, b: [] }
fusion({ a: 1, b: { c: "Salem" } }, { a: 10, x: [], b: { c: "alem" } }); // -> { a: 11, x: [], b: { c: 'Salem alem' } }
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
fusion({ a: 1, b: { c: 'Salem' } }, { a: 10, x: [], b: { c: 'alem' } })
// -> { a: 11, x: [], b: { c: 'Salem alem' } }
fusion({ a: "hello", b: [] }, { a: 4 }); // -> { a: 4, b: [] }
```

Loading…
Cancel
Save