const responses = getResponses();
// Strict equality check
const checkForPlagiarism = (responses, answer) =>
responses.find(v => v.response === answer) ? true : false;
// Check substring in some response
const checkForPlagiarismFuzzy = (responses, answer) =>
responses.find(v => new RegExp(answer, "gi").test(v.response)) ? true : false;
console.log('[exact] "lysosomes are cellular organelles" =>',
checkForPlagiarism(responses, 'lysosomes are cellular organelles'));
console.log('[exact] "Esophagus" =>', checkForPlagiarism(responses, 'Esophagus'));
console.log('[exact] "True" =>', checkForPlagiarism(responses, 'True'));
console.log('[fuzzy] "a membrane-bound organelle" =>',
checkForPlagiarismFuzzy(responses, 'a membrane-bound organelle'));
console.log('[fuzzy] "a membrane-bound stomach" =>', checkForPlagiarismFuzzy(responses, 'a membrane-bound stomach'));
console.log('[fuzzy] "Tru" =>', checkForPlagiarismFuzzy(responses, 'Tru'));
function getResponses() {
return [{
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
}
];
}
.as-console-wrapper { top: 0; max-height: 100% !important; }