# Intermediate Algorithm Scripting: Diff Two Arrays (pseudocode to javascript)

I am doing this challenge which tells you to only gives out the elements that do not co-exist in two given arrays.
I am trying to solve this problem using these steps/logics.

1. `concat` two array into one array `newArray`
2. filter out all the array elements as long as it appeared more than once.

I tried out this array and find that if you have duplicates inside your array, the position of the element will not be updated once it appeared inside an array. See [3] is both position 2 from the console.

so here is my â€śsolutionâ€ť with some pseudocode in it

var arr = [â€śhelloâ€ť,â€śworldâ€ť,3,4,5,62,3,12];

for(let i = 0; i < arr.length; i++){
if(/arr.indexOf(arr[i]) appeared more than once/){
arr.splice(i,1);
}
}

console.log(arr);

how do I convert that pseudocode to javascipt?
am I overly complicating things here?

Itâ€™s not that the position is not being updated, whatâ€™s happening is that youâ€™re searching the indexOf 3, it will return the index of the first 3 it finds, which is in the index 2.

Youâ€™re in the right path by concatenating both arrays, but instead of looking for duplicated elements in that big array, I think itâ€™s easier and simpler if you iterate the big array and check if the element is present in both `arr1` and `arr2`.

1 Like

thanks for the suggestion, I solved the algorithm.