Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #11

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Dev #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions __tests__/utils/QueryProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ describe("QueryProcessor", () => {
"writer in the English language and the world's pre-eminent dramatist."
));
});
test('should return andrewid', () => {
const query = "andrewid";
const response: string = QueryProcessor(query);
expect(response).toBe((
"chenfang"
));
});
});
30 changes: 30 additions & 0 deletions utils/QueryProcessor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ export default function QueryProcessor(query: string): string {
"writer in the English language and the world's pre-eminent dramatist."
);
}
if (query.toLowerCase().includes("andrewid")) {
return (
"chenfang"
);
}
if (query.toLowerCase().includes("name")) {
return (
"Alinaaa"
);
}

if (query.toLowerCase().includes("largest")) {
const matches = query.match(/\d+/g); // Find all numbers in the query
if (matches) {
const numbers = matches.map(Number); // Convert all found strings to numbers
const largest = Math.max(...numbers); // Find the largest number
return largest.toString(); // Return the largest number as a string
}
}

// Handling simple arithmetic expressions
if (query.toLowerCase().includes("plus")) {
// Attempt to extract numbers before and after the word "plus"
const parts = query.match(/(\d+)\s+plus\s+(\d+)/i);
if (parts && parts.length === 3) { // Check if the match was successful and we have the correct parts
const num1 = parseInt(parts[1], 10); // First number
const num2 = parseInt(parts[2], 10); // Second number
return (num1 + num2).toString(); // Perform the addition and return the result as a string
}
}

return "";
}