Items in stock
A JavaScript exercise from Scriptdrill. Solve it with a code editor in your browser that runs your function against example and hidden tests, and it is checked the moment you submit.
The task
Each item looks like `{ name, qty }`. Return the items that are in stock, meaning `qty` is greater than 0, in their original order. A negative `qty` is a back order, not stock.
What this exercise teaches
filter returns a new array with the items that pass the test, in the same order. Comparing with > 0 excludes both zero and negative quantities; a truthiness check would keep the negative ones.
A hint if you get stuck
`filter` keeps the elements for which your callback returns true. Compare `qty` with `> 0` rather than testing it for truthiness.
Try it now, no account needed
This exercise is free. Open it on the practice page, solve it, and get instant feedback with a hint and a worked solution after two tries.
Open this exercise