面试题及其个人做的答案
有更好思路的说一下,不用实际的敲代码,说一下即可,谢谢啊
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> </body> </html> <script type="text/javascript"> var arr=["abd","cba","ba"]; var t=[]; var re=[]; for(var i=0;i<arr.length;i++){ t[i]=arr[i].substr(1)+i; } var temp=t.sort(); for(var i=0;i<arr.length;i++){ var num=parseInt(temp[i].substr(temp[i].length-1)); re[i]=arr[num].charAt(0)+temp[i].substr(0,temp[i].length-1); } document.write(arr); document.write("<br />"+re) </script>