Sorted Union
This activity which I was given was tricky and not easy though I thought of a for-loop that will iterate through but it was difficult to continue from there.
Problem
I was required to write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays.
The program has to return a new array of unique values from two original arrays in the order they show up. So there is not sorting required, and there shouldn’t be any duplicates.
Approach
Assigned an empty array that creates an empty array to store our final result.
first for-loop that iterates through the arguments object to truly made the program work with two or more arrays instead of 3.
A for-loop that loops through the array on the other array.
I have an if-statement which checks if the value is already on the final array, which checks each an every index therefore I push it to the finalArray.
Conslusion
It was not easy as I thought but my first approach before I got help was useful since we got to build on top on it and I am glad because I had a clue of where to start it didn’t become so frustrating as I thought it would be.