Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Sum Numbers by Andrej_Vasilenko
import assert from "assert";
function sumNumbers(test: string): number {
return ( test.match(/\d+\b/g) || [] ).reduce( (sum, current) => sum + +current, 0 );
}
console.log('Example:');
console.log(sumNumbers('hi'));
// These "asserts" are used for self-checking
assert.equal(sumNumbers('hi'), 0); // 0
assert.equal(sumNumbers('who is 1st here'), 0); // 0
assert.equal(sumNumbers('my numbers is 2'), 2); // 2
assert.equal(sumNumbers('This picture is an oil on canvas ' // 3755
+ 'painting by Danish artist Anna '
+ 'Petersen between 1845 and 1910 year'), 3755);
assert.equal(sumNumbers('5 plus 6 is'), 11);
assert.equal(sumNumbers(''), 0);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
May 22, 2020
Comments: