Skip to content

Commit 42ceb0c

Browse files
committed
update addition query to handle multiple additions
1 parent 68519bd commit 42ceb0c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

utils/QueryProcessor.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ export default function QueryProcessor(query: string): string {
1919

2020
const plusMatch = query
2121
.toLowerCase()
22-
.match(/what is\s*(-?\d+(?:\.\d+)?)\s*plus\s*(-?\d+(?:\.\d+)?)\?/);
22+
.match(/what is\s*(-?\d+(?:\.\d+)?(?:\s*plus\s*-?\d+(?:\.\d+)?)+)\?/);
2323
if (plusMatch) {
24-
const left = Number(plusMatch[1]);
25-
const right = Number(plusMatch[2]);
26-
return (left + right).toString();
24+
const sum = plusMatch[1]
25+
.split(/\s*plus\s*/)
26+
.map((value) => Number(value))
27+
.reduce((total, value) => total + value, 0);
28+
return sum.toString();
2729
}
2830

2931
const multiplyMatch = query

0 commit comments

Comments
 (0)