title: Locale based sort in Javascript, sort accented letters and other variants in a predefined way
body: <p>In Finnish we sort <code>W</code> after <code>V</code> (as in English) but because <code>W</code> is not a native Finnish letter, it is considered as a variant of <code>V</code>, which is sorted as it were equal to <code>V</code>, but in cases where the only difference between two words is that <code>V</code> is <code>W</code>, then <code>V</code>-version is sorted first. An example enlights the proper order:</p>
  
  <pre><code>Vatanen, Watanen, Virtanen
  </code></pre>
  
  <p>In Finnish <code>V</code> and <code>W</code> are collated as <code>A</code> and <code>Á</code>. <code>Á</code> is sorted like <code>A</code>, but in cases where it is the only difference, the unaccented one comes first. The same rule is for all other accented letters, but the <code>Å</code>, <code>Ä</code> and <code>Ö</code> are collated separately after Z.</p>
  
  <p><strong>Question: What would be the best algorithm to sort this like <i>variants</i> in a predefined way?</strong> ( eg. <code>[Watanen, Vatanen, Virtanen]</code> to <code>[Vatanen, Watanen, Virtanen]</code> )?</p>
  
  <p>Addition: The question is relevant to extend to cover also other variants in the way they are defined in <a href="http://cldr.unicode.org/index/cldr-spec/collation-guidelines" rel="noreferrer">http://cldr.unicode.org/index/cldr-spec/collation-guidelines</a>, because the technique would in a great probability be the same and the answers to this question benefit the widest possible audience and sort algorithms can be made compatible with collation rules defined in Unicode CLDR. The Unicode CLDR defines three levels of differences between letters: primary level (base letters), secondary level (accented letters) and tertiary level (character case).</p>
  
  <p>I have thought some kind of <i>array preparation</i> like in numerical sort where we could pad all numbers with zeros to make them comparaple as strings. An example: Array <code>[file1000.jpg, file3.jpg, file22.jpg]</code> can be <i>prepared</i> to make it comparable as strings by padding with zeros this way: <code>[file1000.jpg, file0003.jpg, file0022.jpg]</code>. Because of <i>preparation</i> of array, we can sort it very fast using native Array.sort().</p>
  
  <p>The target language is Javascript, which lacks support for collation based sorts, so the custom sort function have to be made self. The algorithm is preferred, but if you have also code it's worth +1.</p>