Your question is Custom Utility Without Prototypes. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
QuickBooks frontend utilities may receive nested category values that need to be flattened before rendering or validation. Implement a custom utility that behaves like JavaScript's Array.prototype.flat, without calling built-in prototype methods such as flat, map, reduce, concat, or join.
Given a list containing values or nested lists and a nonnegative integer depth, return a new list in left-to-right order. Flatten a nested list only when the current remaining depth is greater than zero. Non-list values must be copied into the result unchanged. A depth of 0 returns a shallow copy, preserving nested lists as elements.
The Python implementation should use explicit iteration or recursion and must not mutate the input list.
def flatten_values(values, depth):