Flatten a nested object with keys under a given root prefix
Write a function flattenWithPrefix(obj, prefix) that flattens a nested object into a single-level object. Each key in the resulting object should be a concatenation of the keys from the nested object, prefixed with the specified prefix. The function should handle arbitrary levels of nesting. Object.entries() is handy for walking the keys as you flatten an object with prefix paths.
For example, given the input object:
const input = { a: { b: { c: 1 }, d: 2 } };
The expected output, with each key flattened and prefixed, would be:
{ 'a.b.c': 1, 'a.d': 2 }
The function should be able to traverse through the nested object, concatenating each key with its parent key(s) and the given prefix, to create a new, flattened object structure where each key represents the “path” to its value within the original nested object.