title: How to sort an array of string by similarity to specific key
body: <p>Given is the following:</p>
  <p><code>var theArray: [String] = [&quot;uncool&quot;, &quot;chill&quot;, &quot;nifty&quot;, &quot;precooled&quot;, &quot;dandy&quot;, &quot;cool&quot;]</code></p>
  <p>I want to sort the array by <strong>how similar the words are</strong> to the key word.</p>
  <p><code>var keyWord: String = &quot;cool&quot;</code></p>
  <p>The wanted result would be:</p>
  <p><code>print// [&quot;cool&quot;, &quot;uncool&quot;, &quot;precooled&quot;, ...]</code> and then it does not matter anymore. But the words that <code>are</code> the key or <code>contain it</code> should be the very first objects.</p>
  <p>My closest tryout so far has been:</p>
  <pre><code>let _theArray = entries.sorted { element1, element2 in
  
       return element1.contains(keyWord) &amp;&amp; !element2.contains(keyWord)
  }
  </code></pre>
  <p>But that results in <code>uncool</code> being the first item, then <code>precooled</code> and the most related item <code>cool</code> even comes after <code>nifty </code>.</p>
  <p>What am I missing?</p>