Compare 2 Integer Arrays: Find Non-Shared Values?{[SOLVED]}
347
2
1
-
- olivierth
- Member

- 1129 posts
- Joined: 4月 2017
- Offline
Hi!
I have 2 integer arrays:
A: {3, 46, 23, 31, 49, 1}
B: {23, 3, 14, 1};
...I need to find any values in B that isn't in A: 14
Is there a function for that?
-Olivier
Edited by olivierth - 2025年5月16日 18:53:36
-
- AslakKS
- Member

- 227 posts
- Joined: 2月 2016
- Offline
I would do something like this, loop over B and check if each int is in A
int A[] = {3, 46, 23, 31, 49, 1};
int B[] = {23, 3, 14, 1};
int B_uniq[];
foreach(int B_val; B){
if(find(A, B_val) < 0){
append(B_uniq, B_val)
}
}
i[]@B_uniq = B_uniq; // {14}
-
- olivierth
- Member

- 1129 posts
- Joined: 4月 2017
- Offline
Ohh! I thought the find function was only for strings!
Thanks!