Skip to content

Commit 218f939

Browse files
committed
Add merge optimization for the heck of it
1 parent dddef34 commit 218f939

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

defaultMethods.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,18 @@ const defaultMethods = {
450450
return result ? buildState.compile`!(${result})` : false
451451
}
452452
},
453-
merge: (arrays) => (Array.isArray(arrays) ? [].concat(...arrays) : [arrays]),
453+
merge: (args) => {
454+
if (!Array.isArray(args)) return [args]
455+
const result = []
456+
for (let i = 0; i < args.length; i++) {
457+
if (Array.isArray(args[i])) {
458+
for (let j = 0; j < args[i].length; j++) {
459+
result.push(args[i][j])
460+
}
461+
} else result.push(args[i])
462+
}
463+
return result
464+
},
454465
every: createArrayIterativeMethod('every'),
455466
filter: createArrayIterativeMethod('filter', true),
456467
reduce: {

suites/chained.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,11 @@
5858
},
5959
"result": 149212,
6060
"description": "Max with Logic Chaining (Complex)"
61+
},
62+
{
63+
"description": "Addition Chained w/ Merge",
64+
"rule": { "+": { "merge": [{ "val": "x" }, { "val": "y" }] }},
65+
"result": 6,
66+
"data": { "x": [1, 2], "y": 3 }
6167
}
6268
]

0 commit comments

Comments
 (0)