Skip to content

Commit 71bde17

Browse files
committed
Update QueryProcessor.tsx
1 parent 779ffef commit 71bde17

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

utils/QueryProcessor.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default function QueryProcessor(query: string): string {
2-
// const extract_int = (str) => {
3-
// return str.replace("?", "").replace(","," ").split(" ")
4-
// }
2+
const extract_int = (str: string) => {
3+
return str.replace("?", "").replace(","," ").split(" ").map((x) => parseInt(x)).filter((x)=>!Number.isNaN(x))
4+
}
55
if (query.toLowerCase().includes("shakespeare")) {
66
return (
77
"William Shakespeare (26 April 1564 - 23 April 1616) was an " +
@@ -24,8 +24,8 @@ export default function QueryProcessor(query: string): string {
2424
// }
2525

2626
if (query.toLowerCase().includes("what is") && query.toLowerCase().includes("plus")) {
27-
let numbers = query.replace("?", "").split(" ");
28-
return (parseInt(numbers[2]) + parseInt(numbers[4])).toString()
27+
let numbers = extract_int(query);
28+
return (numbers.reduce(((x,y)=>x+y), 0)).toString()
2929
}
3030

3131
if (query.toLowerCase().includes("what is") && query.toLowerCase().includes("minus")) {

0 commit comments

Comments
 (0)