Js code that sorts strings in a particular alphabetical order

  • 2020-03-30 01:30:10
  • OfStack

, in alphabetical order, for example, to a certain "a", "o", "e", "u" and "y" and "I", please put 'aiye', 'oeu', 'ayo', 'eoyiu', 'yuo', 'you', 'iao these seven sort in alphabetical order according to the given string.

My idea is to equivalent the given 6 letters to 0-5 Numbers respectively, then replace the letters in the 7 strings with the Numbers in 0-5, and then sort them with sort method, the code is 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); 

 
<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" name="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></pre> 
<pre></pre> 

</pre> 

Related articles: