Looking to streamline this code, specifically the declaration of the variable codes
. Is there a way to simplify this?
const numbers = [
{ id1: 1, id2: 2, id3: 3, pos: "a" },
{ id1: 4, id2: 5, id3: 6, pos: "b" },
{ id1: 7, id2: 8, id3: 9, pos: "c" }
];
let codes = {
id1: Math.max.apply(
Math,
numbers.map((n) => {
return n.id1;
})
),
id2: Math.max.apply(
Math,
numbers.map((n) => {
return n.id2;
})
),
id3: Math.max.apply(
Math,
numbers.map((n) => {
return n.id3;
})
)
};
console.log(codes);
I'm aiming to condense this code while retaining the same data structure. Any suggestions on how to implement a loop or simplify further?
Appreciate any assistance!