function string2int(s) { let dic = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9 } return s.split('').map(x => dic[x]).reduce(function (x, y) { return x * 10 + y; }); }
Sign in to make a reply
夏小虫日记
function string2int(s) { let dic = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9 } return s.split('').map(x => dic[x]).reduce(function (x, y) { return x * 10 + y; }); }