Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to convert a string to a mathematical expression programmatically javascript

function addbits(s) {
  var total = 0,
      s = s.match(/[+-]*(.d+|d+(.d+)?)/g) || [];
      
  while (s.length) {
    total += parseFloat(s.shift());
  }
  return total;
}

var string = '1+23+4+5-30';
console.log(
  addbits(string)
)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #convert #string #mathematical #expression #programmatically #javascript
ADD COMMENT
Topic
Name
3+1 =