title: Swift - sorting characters in each string in an array
body: <p>So this question is a follow up to this one: <a href="https://stackoverflow.com/questions/48976065/swift-string-permutations-allowing-the-same-strings/">swift string permutations allowing the same strings</a></p>
  
  <p>There, I asked about all possible mutations that I can make with a defined set of strings. What I am trying to do next is to filter out all results that have the same combination, but in a different order.</p>
  
  <p>So if the input is: <code>["AB", "AC", "CA", "CB"]</code>, the output should be <code>["AB", "AC", "CB"]</code>, since "AC" and "CA" have the same building blocks.</p>
  
  <p>So my thought was to first sort each string alphabetically, and maybe then create a <code>Set</code>.</p>
  
  <p>I am already stuck on the first part :(</p>
  
  <pre><code>let array = ["AB", "AC", "DC", "CA", "CB"]
  print(type(of: array))
  print(array)
  
  let sortedArray = array.map{ $0.sorted() }
  print(type(of: sortedArray))
  print(sortedArray)
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>Array&lt;String&gt;
  ["AB", "AC", "DC", "CA", "CB"]
  Array&lt;Array&lt;Character&gt;&gt;
  [["A", "B"], ["A", "C"], ["C", "D"], ["A", "C"], ["B", "C"]]
  </code></pre>
  
  <p>While I expected for the sortedArray:</p>
  
  <pre><code>["AB", "AC", "CD", "AC", "BC"]
  </code></pre>
  
  <p>Then I thought to join the individual strings back together:</p>
  
  <pre><code>print(array.map{ $0.joined() } )
  </code></pre>
  
  <p>Resulting in <code>ambiguous reference to member 'joined()'</code></p>
  
  <p>But how to fix this I don't understand.</p>
  
  <p>I also saw this one: <a href="https://stackoverflow.com/questions/31904356/swift-sort-characters-in-a-string">swift sort characters in a string</a> where the following code is used:</p>
  
  <pre><code>var nonSortedString = "5121"
  var sortedString = String(Array(nonSortedString.characters).sort())
  </code></pre>
  
  <p>But I don't see how to apply that using <code>map</code> and friends (after converting to Swift 4)</p>
  
  <p>Any help appreciated.</p>