I am breaking my head trying to figure how to achieve what I need. My initial array of objects is 70k objects with 15 attributes each. Through filtering and mapping, I have gotten the data set down to what I think are the relevant parts. I need to return a new array of objects based on each of the 4 properties of each object, with their being duplicate id's and different levels for each code. My filtered data looks like so.
const arr = [{id: "12345", level: "1", current: "Y", code: "1"},
{id: "12345", level: "0", current: "N", code: "1"},
{id: "54321", level: "1", current: "N", code: "201"},
{id: "54321", level: "2", current: "Y", code: "201"},
{id: "54321", level: "3", current: "N", code: "201"},
{id: "54321", level: "0", current: "Y", code: "401"},
{id: "54321", level: "1", current: "N", code: "401"},
{id: "54321", level: "3", current: "N", code: "201"},
{id: "54321", level: "0", current: "N", code: "301"},
{id: "121212", level: "0", current: "N", code: "3"},
{id: "121212", level: "1", current: "N", code: "3"}]
What I need to achieve is for each id for any current of Y for each code, I need to find the max level for that code. So for the example above the resulting output would be an array of objects like so:
const result = [{id: "12345", max: "1", code: "1"},
{id: "54321", max: "3", code: "201"},
{id: "54321", max: "1", code: "401"}]
I'm not even sure if what I want is possible, or if I'm thinking about it the wrong way. I have been racking my brain all morning trying to figure out a solution.
codethat has a 'Y' for eachidI need to find the max of that code for theid. I need the maxlevelfor each code that has a 'Y'