JSFiddle - React, Tailwind, and code Playground

by tchalvakspam

JavaScript

// Original arrays of data.

list1 = ['A', 'B', 'C', 'D', 'E']; 
list2 = ['C', 'E'];


// Dummy matching function to be replaced with more in-depth comparison
function matches(a, b){
    if(a === b){
            return true;
    }
}

// An internally-used array.
lookupArray = {};

for (var j in list2) {
        // Turn the values into keys for easy lookup.
        var loop_value = list2[j];
        lookupArray[loop_value] = loop_value; // Set the value as a key as well.
}

// Loop over one list or another, 
for (var i in list1) {
      // If the key exists in the lookup array, and the match function says that they match, alert us.
      if (
              list1[i] && typeof lookupArray[list1[i]] != 'undefined'
      ) {
          document.writeLn('found ' + list1[i] + ' in both lists');
          break;
     } 
 }