My question is this. Assume I have an array called A
and I only want certain operations to happen depending on a condition. What is more efficient:
I)
A.forEach(x => {
if (condition1) {
//do stuff1
}
else if (condition2) {
//do stuff2
}
else if (condition3) {
//do stuff3
}
});
or
II)
if (condition1) {
A.forEach(x => {
//do stuff1}
)}
}
else if (condition2) {
A.forEach(x => {
//do stuff2}
)}
}
else if (condition3) {
A.forEach(x => {
//do stuff3}
)}
}
or is there a much better way to do what I'm after? Thanks!