Question: I'm starting with a large array containing nested objects (~34,000 items), and I'm polling every 5 seconds, receiving updates to the array (generally 2-3 updates at a time) and the new array only contains items that have changed (so for example, if only 3 items changed, I only get those 3 items in my updated array.)

I tried the following using underscore, but it takes up to 9 seconds, I need like a second or less. 

```
  getUniqueUnion(new, old) {
    return uniq(union(new, old), false, function(item) {
      return item.info.id;
    }); 
  }

```

Anyone have a suggestion for a fast approach? If it helps, the unique key would be info.id, and the only change I'm really looking to detect (reason I need to update the item) is if the inStock value changes. In other words, if the inStock value hasn't changed, I dont need to make any update to that array item. 

Example arrays:

```
const originalData = [
  {
    info: {
      id: 1
    },
    moreInfo: {
      name: 'hamburger',
      inStock: true
    }
  },
  ... // 33,999 more
]

const updatedData = [
  {
    info: {
      id: 1
    },
    moreInfo: {
      name: 'hamburger',
      inStock: false
    } 
  },
  ... // maybe 2 more
]

```

So the final array would include the first item to have moreInfo.inStock === false

Answer: 
After reading your situation, here is my suggestions:

1. Sort your large array. You only have to do this **once**, so don't worry about it. Finding a value in a sorted array is always faster and easier than in an unsorted one.
2. Loop through your `updatedData`, take an item, look for it in your sorted array (`originalData`), **using Binary Search**. Update it as you want.

To see how Binary Search is implemented in javascript, you can refer to this [post](http://oli.me.uk/2013/06/08/searching-javascript-arrays-with-a-binary-search/), or this [one](https://www.nczonline.net/blog/2009/09/01/computer-science-in-javascript-binary-search/).
I was definitely over-complicating this. Here's a solution I came up with, but if anyone knows of something faster I'd appreciate it.

```
function updateArray(latest, current) {
  for (let i = 0, len = current.length; i < len; i++) {    
    for (let g = 0, len = latest.length; g < len; g++) {
      if (latest[g].module.id === current[i].module.id) {
        current[i] = latest[g];
        break;
      }
    }
  }

  return current;
}

```