title: What is the most efficient way to sort an array of strings by another array of strings?
body: <h1>My Question</h1>
  <p>How do I sort an array of strings by by another array of strings in Javascript?</p>
  <h1>Background</h1>
  <p>I am looking for a way to sort an array of strings via another array. Specifically I have a problem where I cannot sort alphabetically or numerically. I know that Javascript supports custom sort functions as seen in this example:</p>
  <pre><code>let numberArray = [40, 1, 5, 200];
  function compareNumbers(a, b) {
    return a - b;
  }
  numberArray.sort(compareNumbers);
  </code></pre>
  <p>I am not sure how a custom string comparison function would work for the problem I am looking at. I have given two example arrays in part 1 and part 2 below. If you need further clarification please ask.</p>
  <h2>PART 1</h2>
  <p><strong>Example arrays:</strong> Note that <code>educationSorted</code> is desired result of sorting <code>education</code> by <code>educationLevel</code>.</p>
  <pre><code>let education = [
    &quot;High School&quot;,
    &quot;Middle School&quot;,
    &quot;Undergrad&quot;,
    &quot;Middle School&quot;,
    &quot;Middle School&quot;,
    &quot;Middle School&quot;,
    &quot;Middle School&quot;,
    &quot;Graduate&quot;,
    &quot;Elementary&quot;,
    &quot;Elementary&quot;,
    &quot;Elementary&quot;,
    &quot;Elementary&quot;
  ];
  
  let educationLevel = [&quot;Elementary&quot;, &quot;Middle School&quot;, &quot;High School&quot;, &quot;Undergrad&quot;, &quot;Graduate&quot;];
  
  let educationSorted = [
    &quot;Elementary&quot;,
    &quot;Elementary&quot;,
    &quot;Elementary&quot;,
    &quot;Elementary&quot;,
    &quot;Middle School&quot;,
    &quot;Middle School&quot;,
    &quot;Middle School&quot;,
    &quot;Middle School&quot;,
    &quot;Middle School&quot;,
    &quot;High School&quot;,
    &quot;Undergrad&quot;,
    &quot;Graduate&quot;
  ];
  </code></pre>
  <h2>PART 2</h2>
  <p>Same general problem but the arrays of strings is replaced by an array of arrays.</p>
  <pre><code>let education = [
    [&quot;Bob&quot;, &quot;High School&quot;],
    [&quot;Alice&quot;, &quot;Middle School&quot;],
    [&quot;Jane Doe&quot;, &quot;Undergrad&quot;],
    [&quot;alex&quot;, &quot;Middle School&quot;],
    [&quot;Mega Alice&quot;, &quot;Middle School&quot;],
    [&quot;Jhon Doe&quot;, &quot;Middle School&quot;],
    [&quot;Minor Bob&quot;, &quot;Middle School&quot;],
    [&quot;Chicken&quot;, &quot;Graduate&quot;],
    [&quot;Minor Chicken&quot;, &quot;Elementary&quot;],
    [&quot;Clones&quot;, &quot;Elementary&quot;],
    [&quot;Clones&quot;, &quot;Elementary&quot;],
    [&quot;Clones&quot;, &quot;Elementary&quot;]
  ];
  
  let educationLevel = [&quot;Elementary&quot;, &quot;Middle School&quot;, &quot;High School&quot;, &quot;Undergrad&quot;, &quot;Graduate&quot;];
  
  let education = [
    [&quot;Clones&quot;, &quot;Elementary&quot;],
    [&quot;Clones&quot;, &quot;Elementary&quot;],
    [&quot;Clones&quot;, &quot;Elementary&quot;],
    [&quot;Minor Chicken&quot;, &quot;Elementary&quot;],
    [&quot;Alice&quot;, &quot;Middle School&quot;],
    [&quot;Mega Alice&quot;, &quot;Middle School&quot;],
    [&quot;Jhon Doe&quot;, &quot;Middle School&quot;],
    [&quot;Minor Bob&quot;, &quot;Middle School&quot;],
    [&quot;alex&quot;, &quot;Middle School&quot;],
    [&quot;Bob&quot;, &quot;High School&quot;],
    [&quot;Jane Doe&quot;, &quot;Undergrad&quot;],
    [&quot;Chicken&quot;, &quot;Graduate&quot;]
  ];
  </code></pre>