← Back to challenges

Grocery Store Prices

JavaScriptHardregexstrings

Instructions

You are given an array of strings consisting of grocery items, with prices in parentheses. Return an array of prices in float format.

Examples

getPrices(["ice cream ($5.99)", "banana ($0.20)", "sandwich ($8.50)", "soup ($1.99)"]) ➞ [5.99, 0.2, 8.50, 1.99]

getPrices(["salad ($4.99)"]) ➞ [4.99]

Notes

See if you can use RegExp to solve (but it's not necessary).

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.