Skip to content

Commit 00b5b17

Browse files
committed
reduce instead of for
1 parent 2f4482e commit 00b5b17

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/execution/execute.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -1098,15 +1098,11 @@ function completeListValue(
10981098
function flattenEPRs(
10991099
eprs: $ReadOnlyArray<ExecutionPartialResultNP<mixed>>,
11001100
): ExecutionPartialResultNP<mixed> {
1101-
const errors = [];
1102-
const data = [];
1103-
for (let i = eprs.length - 1; i >= 0; i--) {
1104-
data[i] = eprs[i][0];
1105-
if (eprs[i][1] && eprs[i][1].length) {
1106-
errors.push(...eprs[i][1]);
1107-
}
1108-
}
1109-
return [data, errors.length ? errors.reverse() : null];
1101+
const errors = eprs.reduce(
1102+
(m, i) => (i[1] && i[1].length ? [...m, ...i[1]] : m),
1103+
[],
1104+
);
1105+
return [eprs.map(i => i[0]), errors.length ? errors : null];
11101106
}
11111107

11121108
/**

0 commit comments

Comments
 (0)