Discuss / JavaScript / string2int

string2int

Topic source

function string2int(s) { var arr = []; for (var i = 0; i < s.length; i++) { arr.push(s[i]); }

return arr.map(function(x) {
  return +x;
}).reduce(function(x, y) {
  return x * 10 + y;
});

}


  • 1

Reply