Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Sum Numbers by ArchTauruS
import assert from "assert";
function sumNumbers(test: string): number {
// your code here
const numbers = test.match(/\b(\d+)\b/g)
return numbers ? numbers.map(Number).reduce((a, b) => a + b, 0) : 0
}
console.log('Example:');
console.log(sumNumbers('hi 1 f2 4'));
// These "asserts" are used for self-checking
assert.equal(sumNumbers('hi'), 0);
assert.equal(sumNumbers('who is 1st here'), 0);
assert.equal(sumNumbers('my numbers is 2'), 2);
assert.equal(sumNumbers('This picture is an oil on canvas ' +
'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!");
Sept. 15, 2020
Comments: