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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
function hexPlus36( string1, string2 ){ let currentIndex = 0; let start = "0"; let end = "Z"; let isAdd = false; let startCharCode = start.charCodeAt(); let endCharCode = end.charCodeAt(); let sum = []; let Lenstring1 = string1.length; let Lenstring2 = string2.length; while( Lenstring1>currentIndex || Lenstring2>currentIndex ){ let addA = startCharCode; if( Lenstring1>currentIndex ){ let currentCharCode = string1.charCodeAt(Lenstring1-currentIndex-1); if( currentCharCode >= startCharCode+9 ){ addA = currentCharCode - "a".charCodeAt() + startCharCode + 10; } else { addA = currentCharCode; } } let addB = startCharCode; if( Lenstring2>currentIndex ){ let currentCharCode = string2.charCodeAt(Lenstring2-currentIndex-1); if( currentCharCode >= startCharCode+9 ){ addB = currentCharCode - "a".charCodeAt() + startCharCode + 10; } else { addB = currentCharCode; } }
let sumCharCode = (isAdd&&1) + addA + addB - startCharCode; if( sumCharCode >= startCharCode + 36 ){ sumCharCode -= 36; isAdd = true; } if( parseInt(sumCharCode) > startCharCode+9 ){ sumCharCode += "a".charCodeAt() - startCharCode - 10; } sum.unshift( String.fromCharCode(sumCharCode) ); currentIndex++; } if( isAdd ) sum.unshift( String.fromCharCode(startCharCode+1) ); return sum.join(""); }
let result = hexPlus36("1","1"); console.log( result );
|