javascript - Finding the sum of a variable amount of numbers in a given string - Stack Overflow

PHOTO EMBED

Sat Dec 04 2021 21:33:17 GMT+0000 (UTC)

Saved by @tolanisirius #javascript

function add (string) {
   let partsArray = string.split("+");
   console.log("parts", partsArray);
   let added = 0;
      
   for (let i=0; i<partsArray.length; i++) {
      console.log("i",parseInt(partsArray[i]));
      added += parseInt(partsArray[i]);
   }

   return added;
}
content_copyCOPY

https://stackoverflow.com/questions/64869167/finding-the-sum-of-a-variable-amount-of-numbers-in-a-given-string