Write a custom function called detectPlagiarism that accepts two parameters: an array of student responses and a snippet of text to check for plagiarism. The function should return true if any of the essay question answers contain the specified text, and false otherwise. Iterate through each essay question response in the array and check if it includes the given text. If a match is found, return true.
Here are some usage examples:
detectPlagiarism(answers, 'spherical vesicles that contain hydrolytic enzymes'); //=> true detectPlagiarism(answers, 'this string does not appear in the responses'); //=> false Hint: Consider using the String .includes() method to help solve this problem.
Important Notes:
Only essay questions should be considered for plagiarism detection. If the snippet of text is found in a non-essay question answer, it should not trigger a true result.
In my code attempts below, I am trying to iterate over the responses within the array to locate the specified studentAnswer string, but so far it consistently returns false. I also experimented with an alternate approach, yet achieved the same outcome.
let answers = [
{
question: 'What is the phase where chromosomes line up in mitosis?',
response: 'Metaphase',
isCorrect: true,
isEssayQuestion: false
},
{
question: 'What anatomical structure connects the stomach to the mouth?',
response: 'Esophagus',
isCorrect: true,
isEssayQuestion: false
},
{
question: 'What are lysosomes?',
response: 'A lysosome is a membrane-bound organelle found in many animal
cells. They are spherical vesicles that contain hydrolytic enzymes that can
break down many kinds of biomolecules.',
isCorrect: true,
isEssayQuestion: true
},
{
question: 'True or False: Prostaglandins can only constrict blood vessels.',
response: 'True',
isCorrect: false,
isEssayQuestion: false
}
];
function detectPlagiarism(array, studentAnswer){
for(let i = 0; i<array.length;i++)
return array[i].response.includes(studentAnswer);
}
function detectPlagiarism(array, studentAnswer){
return array.includes(array => array.response === studentAnswer);
}