Closed matheus-rodrigues00 closed 1 year ago
@matheus-rodrigues00 is this issue already fixed? If not, how will this be different from pick
method in objects.ts, could you give more info?
@NullSploit01 and @GustavoHBO the deepPick method proposal is to also consider nested object properties. Example:
const mock_object: any = {
a: 1,
b: 2,
c: {
d: {
e: 3,
f: 4,
g: 5,
},
},
};
const keys: string[] = ["a", "b", "c.d.e"];
console.log(deepPick(mock_object, keys));
// this log should yield:
const expected_answer = {
a: 1,
b: 2,
c: {
d: {
e: 3,
},
},
};
// every other key inside c.d.e is filtered from the original object.
After that we can even think about improve it to consider array object property filters. Like, suppose we only want the first or second index of an array, like this call:
const keys: string[] = ["a", "b[0]"];
deepPick(mock_object, keys)
// basically I'm saying that b value will be an array, and I only want the first index of it.
One thing one who's going to implement this needs to take care is that multiple properties can be selected from nested object, like:
const keys: string[] = ["a", "b.c.d", "b.c.e"];
deepPick(mock_object, keys)
Oh okay got it, thank you for explaining! Will try to implement it
The pick method implemented by @GustavoHBO works great! It would be even better if we can tell which nested properties we actually want from nested objects.
Method signature: