Chap05 -> Using query parameters -> 1. Create function to simulate a search via web request

master
Jason Zhu 2022-03-30 16:30:54 +11:00
parent cdc8fea5b5
commit 6ccb67ca01
1 changed files with 11 additions and 0 deletions

View File

@ -64,3 +64,14 @@ export const getQuestion = async (
const results = questions.filter((q) => q.questionId === questionId); const results = questions.filter((q) => q.questionId === questionId);
return results.length === 0 ? null : results[0]; return results.length === 0 ? null : results[0];
}; };
export const searchQuestions = async (
criteria: string,
): Promise<QuestionData[]> => {
await wait(500);
return questions.filter(
(q) =>
q.title.toLowerCase().indexOf(criteria.toLowerCase()) >= 0 ||
q.content.toLowerCase().indexOf(criteria.toLowerCase()) >= 0,
);
};