I am currently working on enhancing my reduce function to transform a nested JSON object into a flat list for more convenient searching.
Consider the following JSON:
{
"MovementPatterns": [
{
"Id": "",
"Name": "Warm-up",
...
Here is the code I have been using:
const exercises = data.MovementPatterns.reduce(
(a, {Exercises}) => [...a, ...Exercises, ...a],
[],
);
This code successfully flattens all exercises from each movement pattern into a single list. However, I now need to add the PARENT Movement Pattern ID to each exercise in the JSON.
[
{
"Id": "",
"Name": "Lizard Stretch",
...
I would greatly appreciate any assistance in modifying my reduce function to achieve this additional requirement :)
Thank you!