Skip to content

Commit 3a96b94

Browse files
committed
add endpoint for multiplication
1 parent 112509b commit 3a96b94

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

__tests__/utils/QueryProcessor.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ describe("QueryProcessor", () => {
3939
const response: string = QueryProcessor(query);
4040
expect(response).toBe("117");
4141
});
42+
43+
test("should return number that is both a square and a cube", () => {
44+
const query = "Which of the following numbers is both a square and a cube: 3059, 2190, 3044, 195, 81, 4096?";
45+
const response: string = QueryProcessor(query);
46+
expect(response).toBe("4096");
47+
});
4248
});

utils/QueryProcessor.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ export default function QueryProcessor(query: string): string {
2626
return (left + right).toString();
2727
}
2828

29+
const multiplyMatch = query
30+
.toLowerCase()
31+
.match(/what is\s*(-?\d+(?:\.\d+)?)\s*multiplied by\s*(-?\d+(?:\.\d+)?)\?/);
32+
if (multiplyMatch) {
33+
const left = Number(multiplyMatch[1]);
34+
const right = Number(multiplyMatch[2]);
35+
return (left * right).toString();
36+
}
37+
2938
const largestNumbersMatch = query
3039
.toLowerCase()
3140
.match(/which of the following numbers is the largest:\s*(.+)\?/);

0 commit comments

Comments
 (0)