Chap05 -> Using query parameters -> 1. Create function to simulate a search via web request
parent
cdc8fea5b5
commit
6ccb67ca01
|
@ -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,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue