For example, give a specific alphabetical order, "a", "O", "E", "U", "Y", "I", please sort the 7 strings of ' Aiye ', ' oeu ', ' ayo ', ' Eoyiu ', ' yuo ', ' You ', ' Iao ' in the given alphabetical order.
My idea is to give those 6 letters equivalent to 0-5, and then replace the letters in the 7 strings with the numbers in 0-5, then sort them by the sort method as follows:
Copy Code code as follows:
var word = [' Aiye ', ' oeu ', ' ayo ', ' Eoyiu ', ' yuo ', ' You ', ' Iao '];
var obj = {A:0,o:1,e:2,u:3,y:4,i:5};
var obj1 = {0: ' A ', 1: ' O ', 2: ' E ', 3: ' U ', 4: ' Y ', 5: ' I '};
For (var index in Word) {
var word1 = Word[index];
var word3 = "";
for (var i = 0; i< word1.length i + +) {
Word3 + = Obj[word1[i]];
};
Word[index] = Word3
}
Word.sort ();
For (var index in Word) {
var word1 = Word[index];
var word3 = "";
for (var i = 0; i< word1.length i + +) {
Word3 + = Obj1[word1[i]];
};
Word[index] = Word3
}
Console.log (word);
Copy Code code as follows:
<pre code_snippet_id= "173179" snippet_file_name= "blog_20140127_1_" 4210131 "></pre><pre code_snippet_id=" 173179 "snippet_file_name=" blog_20140127_1_4210131 "code" class= "html" ><span class= "Source-code" style= "Font-family:consolas, ' Lucida Console ', monospace; White-space:pre-wrap "><span style=" Font-family:consolas, ' Lucida Console ', monospace; White-space:pre-wrap "></span></span><pre code_snippet_id=" 173179 "Snippet_file_name=" Blog_ 20140127_1_4210131 "></pre>
<pre></pre>
<pre></pre>
<pre></ Pre>
<pre></pre>
<pre></pre>
<pre></pre>
<PRE></PR E>
<pre></pre>
</pre>