Sorted Union_____

function uniteUnique(arr) {

// Problem Summary: Take the last argument in "arr" and check to see if the numbers are in the arrays that come before it, if they are there in the same order...keep them, if duplicates are there in a different order, get rid of them. Lastly, a number in the last arguments array is not in the arrays before it at all, add it 

// creates empty array to push final answer
var finalArray = []; 
// Looks through all arguments 
for (let i = 0; i < arguments.length; i += 1) 
// Looks through all arrays numbers
for (let j = 0; j < arr.length; j += 1)


console.log(uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]));

I need help. I think I basically need to make an if statement but I feel lost. Hate how low my confidence is when it comes to coding, sucks feeling lost for every problem in this section. Intermediate Algorithm Scripting section is kicking my ass :sob:

I think you need to first try to write out an algorithm that satisfies the challenge requirements first before writing code. With what you have written so far in code, it is impossible to understand what direction you are trying to go.

Walk us through the algorithm (basic steps) without writing any code and we can help guide you.

function uniteUnique(arr) {

// Step 1: Creates empty array to push final answer into
var finalArray = []; 
// Step 2: Create a for loop to look through all arguments 
for (let i = 0; i < arguments.length; i += 1) 
// Step 3: Create a for loop to look through all arrays numbers
for (let j = 0; j < arr.length; j += 1)
// Step 4: If the last array has duplicate numbers in other arrays, then remove the duplicates
// Step 5: Have the remaining numbers come together to make one array

console.log(uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]));

Are these steps accurate?

Not enough steps and not enough details in steps.

The first two steps do not explain why you are doing what you say you are doing.

Explain in your own words how you would manually determine what the sorted union of the following arrays:

[1, 3, 2], [5, 2, 1, 4], [2, 1]
function uniteUnique(arr) {

//Step 1: Check to see if the numbers in the last array exist in arrays before it
//Step 2: If duplicates exist in the exact same order as the final array...remove them && if it's a new number...include it in the final answer at the end of the array
// Example ([6, 7, 8], [5, 6, 7]) should return [8,5]

console.log(uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]));

Is this enough detail?

Break this down into smaller steps. How would you accomplish this? Remember, I am not talking about code. I am wanting you to explain it with an actual example. What are the actual steps you would take to accomplish this particular task you wrote above?

Walk through each number of each array for uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]) and explain what is being compared. Once you can walk through your algorithm with an actual example and get the correct answer, then you have the correct algorithm to be able to start writing code.

To accomplish that task, the actual steps would be me having an understanding of values. Then I could go by each number and see if it matches the numbers in the final array. Not talking about coding, the simplest way I could explain it, as if I am explaining it to a kid, would be first to understand numbers so you are able to go by each number and see if it is equal to any of the numbers in the final argument/array. We would be comparing to see if the number is less than, greater than, or equal to the numbers in the final argument/array.

Now try to explain in as a process that has specific steps. You are still talking in generalities but not explaining the logical steps you would actually take to accomplish the task.

  1. Create a spot to eventually push all the correct numbers to
  2. Check how many arguments exist (because unlike this example, it is not always [0,1,2]…sometimes it’s just [0,1]
  3. Also check every array
  4. Push all the numbers into the final array if the numbers aren’t already there

This is probably not what you want, I promise I’m trying. I just don’t know how to explain it the way you want. I understand what the problem wants, but I guess I’m not good at breaking it down into specific steps

Explain how you would do this and how that helps you solve the problem.

Check every array for what exactly? What are you checking?

How do you know if they aren’t already there.

  1. Create a spot to eventually push all the correct numbers to
  2. Check how many arguments exist (because unlike this example, it is not always [0,1,2]…sometimes it’s just [0,1]
  • How this helps solve the problem? If you know how many arguments, then you know the last argument is the one you will compare to the others
  1. Also check every array
  • For what? Checking all the numbers inside each array to see if duplicates from the last argument are in there
  1. Push all the numbers into the final array if the numbers aren’t already there
  • How do you know? I honestly don’t know, this problem is making me more and more confused

Nevermind, thanks for the help, I got it :slight_smile: