← Back to challenges

Sum of Negative Integers

JavaScriptHardstringslanguage_fundamentalsregexalgorithms

Instructions

Create a function that takes a string containing integers as well as other characters and return the sum of the negative integers only.

Examples

negativeSum("-12 13%14&-11") ➞ -23
// -12 + -11 = -23

negativeSum("22 13%14&-11-22 13 12") ➞ -33
// -11 + -22 = -33

Notes

There is at least one negative integer.

javascript
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.
Next: Opposite House 🏘️ β†’