给定一个包含大写英文字母和数字的句子,找出这个句子所包含的最大的十六进制整数,返回这个整数的值。数据保证该整数在int表示范围内
function hex2int(hex){ var len=hex.length,a=new Array(len),code; for (var i=0;i<len;i++){ code = hex.charCodeAt(i); if (48<=code&&code<58){code-=48;} else{code=(code&0xdf)-65+10;} a[i]=code; } return a.reduce(function(acc,c) {acc=16*acc+c;return acc;},0); } function solve(s) { let array = s.match(/[1-9A-F][\dA-F]*/g); if (array==null){return 0;} array.sort((a,b)=>{return a.length-b.length}).reverse(); let strLen = array[0].length; let arrLen = array.length; let hexArray = []; for(let i=0;i<arrLen;i++) { if(array[i].length<strLen)break; hexArray.push(hex2int(array[i])); } hexArray.sort().reverse(); return hexArray[0]; }