哪位高手能把这段java代码转换成JS代码?比较急。。。十分感谢!
static String[] wi = {"3","7","9","10","5","8","4","2"};
static char[] ai = {'0','1','2','3','4','5','6','7','8','9','A',
'B','C','D','E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T','U','V','W',
'X','Y','Z'};
static String[] bi = {"0","1","2","3","4","5","6","7","8","9","10",
"11","12","13","14","15","16","17","18","19","20","21",
"22","23","24","25","26","27","28","29","30","31","32",
"33","34","35"
};
public static String getAi(char s){
for(int i = 0; i < 35; i++){
if (ai[i] == s){
return bi[i];
}};
return "";
}
public static boolean dwdmjym(String dwdm, char[] rechar){
int ModResult;
int sum = 0;
String s, h;
for(int j = 0; j < dwdm.length() - 1; j++){
s = getAi(dwdm.charAt(j));
if (s.equals("")){
return false;
}
else
{
sum += Integer.parseInt(s) * Integer.parseInt(wi[j]);
}
}
ModResult = sum % 11;
switch(ModResult){
case 1: rechar[0] = 'X'; break;
case 0: rechar[0] = '0'; break;
default:
h = String.valueOf(11 - ModResult);
rechar[0] = h.charAt(0);
}
return true;
}
public static boolean dwdmjy(String dwdm){
char[] rechar = new char[1];
boolean rs;
String tempdwdm = "";
for(int i = 0; i < 8; i++){
tempdwdm += dwdm.charAt(i);
}
rs = dwdmjym(tempdwdm, rechar);
if(rs){
if (rechar[0] != dwdm.charAt(8))
return false;
else
return true;
}
else
return false;
}
------解决方案--------------------JScript code
//楼主试下
var wi = ["3","7","9","10","5","8","4","2"];
var ai = ['0','1','2','3','4','5','6','7','8','9','A',
'B','C','D','E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T','U','V','W',
'X','Y','Z'];
var getAi = function(s){
for(var i = 0; i < 35; i++){
if (ai[i] == s){
return bi[i];
}
};
return "";
};
var dwdmjym = function( dwdm,rechar){
var ModResult;
var sum = 0;
var s, h;
for(var j = 0; j < dwdm.length() - 1; j++){
s = getAi(dwdm.charAt(j));
if (s == ""){
return false;
}
else
{
sum += parseInt(s) * parseInt(wi[j]);
}
}
ModResult