⛄Snowberb⛄ – 12-54 Jan 27

What's a better way to do this instead of nesting 2 loops?
for (const template of instrumentTemplates) {
const { instrumentTypeId, name, instrumentTemplate } = template;

for (const instrument of instruments.data) {
if (instrument.instrumentTypeId === instrumentTypeId) {
instrumentsWithTemplate.push({ ...instrument, instrumentTemplate, instrumentType: name });
}
}
}
for (const template of instrumentTemplates) {
const { instrumentTypeId, name, instrumentTemplate } = template;

for (const instrument of instruments.data) {
if (instrument.instrumentTypeId === instrumentTypeId) {
instrumentsWithTemplate.push({ ...instrument, instrumentTemplate, instrumentType: name });
}
}
}
UU
Unknown User446d ago