一些简单代码的解释

时间:2016-10-20 21:35:15

标签: html string salt

我正在尝试理解一小段代码。有人可以解释它到底发生了什么。它是否将连续弦上的弦移到右边?

salt = '40cf738d702c78d8939da5e8cfd324ae';
str_overral = salt;
str_overral = str_overral.replace(/[^a-z0-9]/gi, '').toLowerCase();
str_res='';
for (i=0; i<str_overral.length; i++) {
    l=str_overral.substr(i,1);
    d=l.charCodeAt(0);
     if ( Math.floor(d/2) == d/2 ) {
       str_res+=l;
    } else {
       str_res=l+str_res;
    }
}

1 个答案:

答案 0 :(得分:1)

新字符串如果使用偶数字符构建到结尾/右边(我的意思是字符的代码),而奇数字符则转到开头/左边

&#13;
&#13;
salt = '40cf738d702c78d8939da5e8cfd324ae';
str_overral = salt;
str_overral = str_overral.replace(/[^a-z0-9]/gi, '').toLowerCase();
str_res='';
for (i=0; i<str_overral.length; i++) {
    l=str_overral.substr(i,1);
    d=l.charCodeAt(0);
    console.log('str['+i+']: "' + l + '" ('+d+')');
     if ( Math.floor(d/2) == d/2 ) {
       console.log('even, pushing to the end/right/back');
       str_res+=l;
    } else {
       console.log('odd, pushing to the beginning/left/front');
       str_res=l+str_res;
    }
    console.log('res: "' + str_res + '"');
}
&#13;
&#13;
&#13;