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:

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?

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?

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.

  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

  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:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.