Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Extract Number Groups

Beyond the Courseeasy

Implement `extractNumbers(s)` returning an array of the digit-runs found in `s`, or an empty array if there are none.

Sample tests

Input: extractNumbers("a12b345")
Output: ["12","345"]
Input: extractNumbers("abc")
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • match returns null (not []) when nothing matches.

Learning resources

  • MDN: Regular expressions
Visualize this concept: Regular Expressions →
Approach & explanation (try first)

Matching /\d+/g collects each run of digits; the || [] guards the no-match case.

Loading...
⌘/Ctrl + Enter

Run your code to see results.