-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayDiff.ts
More file actions
51 lines (39 loc) · 1.26 KB
/
arrayDiff.ts
File metadata and controls
51 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
*
* Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
It should remove all values from list a, which are present in list b keeping their order.
arrayDiff([1,2],[1]) == [2]
If a value is present in b, all of its occurrences must be removed from the other:
arrayDiff([1,2,2,2,3],[2]) == [1,3] a
* @param {*} b
* @returns
*/
const arrayA: string[] = ['Joao', 'Maria', 'Pedro', 'Carla']
const arrayB: string[] = ['Ricardo', 'Maria', 'Pedro', 'Joao']
for (let i: number = 0; i < arrayA.length; i++) {
for (let j: number = 0; j < arrayB.length; j++) {
const valueA: string = arrayA[i]
const valueB: string = arrayB[j]
if (valueA === valueB) {
console.log(valueA)
break
}
}
break
}
// function arrayDiff(a, b) {
// // tem que remover os itens de A que existem em B e manter a ordem.
// b.forEach((vb) => {
// a.find(va => {
// if (va === vb) {
// const idx = a.indexOf(vb)
// a[idx] = ""
// }
// })
// })
// a = a.join("").split("")
// return a.map(x => {
// return parseInt(x)
// })
// }
// console.log(arrayDiff([1, 2, 3], [1]))