Create a function called plagiarismChecker that requires two parameters: an array containing the students' responses, and a small snippet of text

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);
 }

Answer №1

To detect plagiarism in student answers, utilize the .some method. It's crucial to verify if the question is an essay type before considering it as potential plagiarism:

function scanForPlagiarism(questionsArray, answer){
    return questionsArray.some(question => question.isEssayQuestion && question.response.includes(answer));
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using res.sendfile in a Node Express server and sending additional data along with the file

Can a Node.JS application redirect to an HTML file using the res.sendFile method from express and include JSON data in the process? ...

The AJAX call is not being identified correctly

I am facing an issue with my search result pagination wherein the page reloads instead of loading via AJAX when using the pagination. The search results are correctly loaded through partial view with AJAX, but the pagination triggers a non-ajax request cau ...

Error occurs in console when using .getJSON with undefined JSON, but does not happen when using embedded data

Can someone help me understand why I'm getting an 'undefined' response when I use console.log(tooltipValues), but there's no issue with console.log(tooltipJSON). I've noticed that when I embed the data directly in my JS code, ever ...

What's the reason for fadeIn() not functioning properly?

Here's the HTML code I'm working with: <!DOCTYPE html> <html> <head> <title>Furry Friends Campaign</title> <link rel="stylesheet" type="text/css" href="styles/my_style.css"> </head ...

Where is the appropriate location to insert a <script> tag in NextJs?

I am facing a challenge in my NextJs application when trying to include the <script> code. I attempted to add it in a .js file but it did not work as expected. In traditional React applications, we typically use the index.html file to incorporate sc ...

Tips for updating the bottom color of Material-UI TextField without relying on the <MuiThemeProvider> component

I am facing an issue with a Material UI TextField component that is placed on a dark background. I need to change the text and line colors to red for only this particular instance, while leaving the rest of the TextFields unaffected. My project utilizes @ ...

When you try to remove an element from an array by its index in Vue JS, the outcome may not be

Here is an array that I have: var hdr = ("name", "date", "start_time", "selling_item", "total_call", "end_time", "ad_num", "area", "order_num"); //this data comes from the database Now, I need to rename these array elements according to prope ...

Encountered a 404 error while trying to install body-parser

Hey there, I'm new to this and ran into an issue while trying to install the body-parser package. Can you please guide me on how to resolve this problem? D:\Calculator>npm install body-paeser npm ERR! code E404 npm ERR! 404 Not Found - GET htt ...

The Jquery script is ineffective for newly added elements

After creating an Ajax Form that functions well, I noticed that when the result of the form is another form, my script does not work for the new form generated. Is there a way to make the new form function like the old one? $(document).ready(function() ...

Creating trails by following the cursor's movement in KineticJS

Currently, I am working on a drawing application using KineticJS. While I have successfully used it to draw shapes and straight lines by following the method outlined in KineticJS - Drawing Lines with Mouse, I now need to draw a line along the mouse's ...

A guide on incorporating JSX file rendering in Flask

I am currently working on integrating React Contact form with MYSQL Workbench using Flask. I have set up the database initialization and model using SQLAlchemy, but I am encountering an issue with the render_template function. Is it possible to render th ...

Retrieving an Instance of Google Maps Object with the Help of JQuery

I'm currently working on a script that, when executed, will retrieve an instance of a Google Maps object from the webpage using JQuery. For example, if there is a map present on the page, it will be structured like this: <div class="map">....& ...

What could be causing my select tags to appear incorrectly in Firefox and IE?

With the help of Jquery, my goal is to dynamically populate a select field when it is in focus, even if it already has a value. Once populated, I want to retain the previous value if it exists as an option in the newly populated field. Although this works ...

Preventing the page from scrolling to the top while utilizing an Angular-bootstrap modal and a window position:fixed workaround on an iPad

It's common knowledge that there is a bug in bootstrap modals on certain devices, causing the page behind the modal to scroll instead of the modal itself (http://getbootstrap.com/getting-started/#support-fixed-position-keyboards) An easy fix for this ...

Convert the jQuery functions click(), hide(), and fadeIn() into their equivalent native JavaScript functionalities

I'm determined to speed up my page by reducing requests. Does anyone have a solution for keeping the functionality of the code below without having to load the entire JQuery library? $("#div1").click(function () { $("#div2).hide(); $("#div3). ...

Guide on integrating a third-party API with React using Express

I'm facing an issue with my React app trying to make a get request to my Express app, which then sends a get request to a third party API to fetch stock prices. Even though the Express app is logging the correct data, I am getting an empty response fr ...

Display search results in Rails without needing to refresh the entire tab

I have a search functionality incorporated within a Bootstrap tab, and I aim to display the search results dynamically without reloading the entire page, specifically within the tab itself. Despite adding 'remote: true' to the form_tag and incor ...

Trouble with jQuery event.keyCode in detecting alphanumeric characters

I recently developed a script that is supposed to detect the key the user clicks and perform an action based on whether it is alphanumeric. However, I am encountering an issue as the script does not seem to be working as expected, and I am not receiving an ...

Error: The module ./lib/helpers could not be located in NWJS

Whenever I attempt to run my application on NWJS, I encounter a problem. Upon checking the NWJS devtools console, I am presented with the error message Uncaught error: Cannot find module './lib/helpers/'. At the end of this particular line in the ...

The appearance of the circle in Safari is rough and lacks smoothness

My circle animation works perfectly on Google Chrome, but when I switch to Safari the edges appear faded and blurry. I tried adding "webkit" to fix it, but had no luck. Is there a compatibility issue with Safari and CSS animations? Here is my code: Snapsh ...