DEV Community

Discussion on: JavaScript Coding Challenge #2: Add all Integer in a string using JavaScript.

Collapse
 
kafiil profile image
Kafil

Great.
You can do this in a single line of code, but that is a little harder to read.

const result = '1bn22vg4n62'.match(/\d+/g).reduce((acc,e)=>acc+parseInt(e),0);
console.log(result) // 89
Collapse
 
ritikrana profile image
Ritik Rana

Great. That can be done. 👌👌
but they are 2 lines.😉😁✌

Collapse
 
kafiil profile image
Kafil

haha 😊

Collapse
 
giacomocerquone profile image
Giacomo Cerquone

yes I'd have done the same and no, I don't believe this is harder to read than the posted code :)