Skip to content

Commit 92221c1

Browse files
committed
Replace some for-loops by map/reduce functions
1 parent 233ca8d commit 92221c1

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

sql.pegjs

+4-20
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,11 @@
106106
}
107107

108108
function createList(head, tail) {
109-
var result = [head];
110-
for (var i = 0; i < tail.length; i++) {
111-
result.push(tail[i][3]);
112-
}
113-
return result;
109+
return [head, ...tail.map(item => item[3])];
114110
}
115111

116112
function createBinaryExprChain(head, tail) {
117-
var result = head;
118-
for (var i = 0; i < tail.length; i++) {
119-
result = createBinaryExpr(tail[i][1], result, tail[i][3]);
120-
}
121-
return result;
113+
return tail.reduce((result, item) => createBinaryExpr(item[1], result, item[3]), head);
122114
}
123115

124116
var cmpPrefixMap = {
@@ -218,11 +210,7 @@ select_stmt_nake "SELECT statement"
218210
// MySQL extensions to standard SQL
219211
option_clause
220212
= head:query_option tail:(__ query_option)* {
221-
var opts = [head];
222-
for (var i = 0, l = tail.length; i < l; ++i) {
223-
opts.push(tail[i][1]);
224-
}
225-
return opts;
213+
return [head, ...tail.map(item => item[1])];
226214
}
227215

228216
query_option
@@ -1115,11 +1103,7 @@ var_decl
11151103

11161104
mem_chain
11171105
= l:('.' ident_name)* {
1118-
var s = [];
1119-
for (var i = 0; i < l.length; i++) {
1120-
s.push(l[i][1]);
1121-
}
1122-
return s;
1106+
return l.map(item => item[1]);
11231107
}
11241108

11251109
data_type

0 commit comments

Comments
 (0)