title: Comparing two objects with a hash
body: <p>I recently had to compare two arrays of objects and identify the similar ones, same as taking the intersection of two sets.</p>
  
  <pre><code>// List A
  
  const listA = [
    { name: 'John', age: 22, gender: 'male', city: 'Boston', sport: 'Basketball' },
    { name: 'Jane', age: 25, gender: 'female', city: 'Chicago', sport: 'Football' },
    ...
  ]
  </code></pre>
  
  <pre><code>// List B
  
  const listB = [
    { name: 'Tom', age: 20, gender: 'male', city: 'New York', sport: 'Soccer' },
    { name: 'Jane', age: 25, gender: 'female', city: 'Chicago', sport: 'Football' },
    ...
  ]
  </code></pre>
  
  <p>The items in both <code>ListA</code> and <code>ListB</code> don't have any unique <code>id</code> attribute. And the two objects can only be considered similar if ALL of their <code>key-value</code> pairs match. In the above example, <code>Jane</code> is a match. </p>
  
  <p>Now, I understand that <a href="https://stackoverflow.com/questions/201183/how-to-determine-equality-for-two-javascript-objects">Object Deep Matching</a> is a well-known problem in JS. For this scenario, I took a different route and calculated hash of every object in both the lists. To calculate the hash, I took the <code>value</code> of every key and passed it to a standard SHA256 hashing function. For example, the hash of first object in <code>listA</code> would be as following.</p>
  
  <pre><code>const objectToHash = { name: 'John', age: 22, gender: 'male', city: 'Boston', sport: 'Basketball' };
  
  // Extract the values
  const plainText = 'John22maleBostonBasketball'
  
  // Hash it
  const hashed = sha256(plainText) // output: dd3defj3434j23rfjf2402439432
  </code></pre>
  
  <p>This way, I have two lists of hashes (or strings) and comparing them becomes easier. <strong>Unless two objects are fully identical, their hash won't be the same.</strong> I understand that calculating hashes is computationally intensive but that's not a problem for my use case.</p>
  
  <p>Am I missing something?</p>