Sniberb
Sniberb2y ago

⛄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 });
}
}
}
1 Reply
reactibot
reactibot2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1068514222096527412 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26