There are arrays A
and B
. We need to add to array C
all the values of arrays A
and B
that are equal in both value and indexes.
A = [a,b,c], B = [c,b,a], C = [b]
Also: to add to array D
all unique values from array A
that are contained in array B
.
A = [d,a,b,c], B = [c,b,a,a], D = [a,b,c]
Is it possible to do this without a nested loop? I can handle the first task, but how do I fill D with values?
for (let i = 0; i < a.length; i++) {
if (b[i] === a[i]) {
c.push(a[i]);
} else if() {
// Some code
}
}