Skip to content

Commit ac17895

Browse files
committed
reduce instead of for
1 parent 0dc4d51 commit ac17895

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/execution/execute.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,15 +1093,11 @@ function completeListValue(
10931093
function flattenEPRs(
10941094
eprs: $ReadOnlyArray<ExecutionPartialResultNP<mixed>>,
10951095
): ExecutionPartialResultNP<mixed> {
1096-
const errors = [];
1097-
const data = [];
1098-
for (let i = eprs.length - 1; i >= 0; i--) {
1099-
data[i] = eprs[i][0];
1100-
if (eprs[i][1] && eprs[i][1].length) {
1101-
errors.push(...eprs[i][1]);
1102-
}
1103-
}
1104-
return [data, errors.length ? errors.reverse() : null];
1096+
const errors = eprs.reduce(
1097+
(m, i) => (i[1] && i[1].length ? [...m, ...i[1]] : m),
1098+
[],
1099+
);
1100+
return [eprs.map(i => i[0]), errors.length ? errors : null];
11051101
}
11061102

11071103
/**

0 commit comments

Comments
 (0)