What is the best way to eliminate a specific item from an array of objects within a function?

1. When utilizing the findUnsubmitted function with an array of submission objects, a specified date, and student names array, the function returns the names of students who have not completed any quiz on that particular date.

  1. If the findUnsubmitted feature does not detect any student names, it will return an empty array.

Upon console.log of the findUnsubmitted function, only [ 'Kevin', 'Nivek', 'John' ] is being returned; however, in this scenario, only Kevin and John should be part of the result.

const submissions = [
    {
        quizName: "Quiz 1",
        quizModule: "Math",
        quizScore: 100,
        studentId: 001,
        studentName: "Kevin",
        submissionDate: "March 24, 2022"
    },
    {
        quizName: "Essay",
        quizModule: "English",
        quizScore: 0,
        studentId: 023,
        studentName: "Nivek",
        submissionDate: "April 1, 2022"
    },
    {
        quizName: "Quiz 2",
        quizModule: "Science",
        quizScore: 71.59485,
        studentId:023,
        studentName: "John",
        submissionDate: "May 24, 2022"
    }

]

const filterByDate = (specificDate, submission) => {
    return submission.filter((sub) => sub.submissionDate === specificDate)
}

const findUnsubmitted = (specificDate, names, submission) => {
    const date = filterByDate(specificDate, submission);
    const unsubmitted = names;
    for(let i = names.length - 1; i >=0; i--) {
        const student = date[i];
        if(student == names.studentName){
            submissions.splice(i, 1);
        }
        return unsubmitted;
        }
}

console.log(findUnsubmitted('April 1, 2022', ['Kevin', 'Nivek', 'John'], submissions));

Answer №1

If you simply wish to retrieve a list of student names who have not completed any quizzes on the specified date, keep it straightforward.

In the function called findUnsubmitted, there is no need to utilize the names variable.


To modify the code in the filterByDate function:

const filterByDate = (specificDate, submissions) => {
     return submissions.filter((submission) => submission.submissionDate !== specificDate)
}

Also, update the findUnsubmitted function like this:

const findUnsubmitted = (specificDate, submissions) => {
      const filteredSubmissions = filterByDate(specificDate, submissions);
      if (!filteredSubmissions) return [];
      return filteredSubmissions.map(submission => submission.studentName);
}

I hope this explanation aids you in your task.

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

Is there a way to specify the login response details when making an Angular API request?

I am currently using Angular to connect to my backend login service. However, I am facing an issue with setting the popup message when the username or password is incorrect. I want to display the detailed message from the API on my login page when any erro ...

Flipping over every single card, but only desire to flip them one at a time

My attempt to flip these cards individually has resulted in them all flipping together. I suspect there may be an error in my JavaScript code. In the original code, I used images in front and an unordered list in the back, but here I have simplified it t ...

Is there a way to customize the color of a MUI styled component?

I have a customized MUI component that displays a circular badge in green. const StyledGreenBadge = styled(Badge)(({ theme }) => ({ '& .MuiBadge-badge': { backgroundColor: '#44b700', color: '#44b700', ...

In React, facing difficulty in clearing setTimeout timer

After clicking the button, I want my code to execute 3 seconds later. However, I'm having trouble achieving this. It either runs immediately or doesn't stop running. <Button onClick={setTimeout(() => window.location.reload(false), 4000), cl ...

Ensure that confirmation is only prompted in ASP.NET when necessary

I am faced with a scenario where I need to handle the value of Session["actionMode"] in conjunction with a button click event. Here is what I currently have implemented in my code: protected void Button1_Click(object sender, EventArgs e) { if ((int)S ...

.NET Bingo: Converting String to Array and Variable Setting

I have a collection of thirty random numbers stored in a single cell in a database, separated by spaces. Currently, I am evaluating and displaying them individually in a row like this: <%# Eval("winning_numbers").ToString().Split(' ')[0]% ...

Combining two 2D arrays based on specific conditions of their column values

I need help merging two 2D NumPy arrays based on a specific condition. Consider the following arrays: A=[[100.121,200.129,1,2,3], [105.343,203.347,2,2,1], [107.426,201.657,1,3,1], [100.121,300.010,1,1,1]] and B=[[107.426,201,675,80], [100.121, ...

API for controlling a 360-degree video camera in Three.js

I have been exploring this demonstration: utilizing the given code snippet: let camera, scene, renderer; let isUserInteracting = false, lon = 0, lat = 0, phi = 0, theta = 0, onPointerDownPointerX = 0, ...

Vibrant progress bar design with CSS

Could someone assist me in coding a multicolor progress bar? I would like it to display red when the progress is less than 50, green when the progress is between 50 and 90, and blue when the progress is between 90 and 100. How can I achieve this? ...

Learn the steps to assign a Base64 URL to an image source

I am currently facing an issue with an image that is being used with angular-cli: <img src="" style="width: 120px; padding-top: 10px" alt="" id="dishPhoto"> The image has a Base64 url named imgUrl. My intention is to set the image source using the ...

PHP code to store the start and end dates of a week in an array

Can someone help me with PHP code to format the start and end date of a week like this? Range: 16-Jan-2018 to 22-Jan-2018 I have the start and end dates, but I'm struggling to store them in an array for multiple weeks under one index. For example: ...

Guide to arranging an object in ascending order based on a key's value using JavaScript

Is there a way to sort the following values: 1, 99, 1, 50 in javascript? Given the input: var map = {test:1, test2:99, test3:1, test4: 50} The desired output is: {test2:99, test4:50, test3:1, test:1} This is the approach I have attempted: function sort ...

What is the most efficient method for iterating through a 2-dimensional array row by row in PHP?

I have a 2D array and I need to insert multiple data into a table using a loop. Here is the data: $data['id'] = array([0] => '1', [1] => '2'); $data['name'] = array([0] => 'Ben', [1] => ' ...

Touch target for scrollbars

While developing the modal in HTML, I encountered an issue where keyboard-only users cannot access all content within the modal. I came across a note stating that the scrollbar touch target should be 44px by 44px. I tried reading this documentation https ...

"Within the boundaries of two tags, eliminate any spaces when using the display property set

I'm a bit confused about the behavior of display:inline-block. I noticed that when I use inline-block, it displays content in a smaller space across two tags. However, when I switch to using float: left, everything works fine. Does anyone have an ide ...

Is there a way to customize the slicing of *ngFor in a component according to the components it is being injected into?

This code snippet represents a component that needs to be included in other components: <div class="row"> <div class="col-12 [...]" *ngFor="let course of courses"> <div class="card"> ...

Combining two associative arrays in PHP

I am facing an issue with two separate arrays. Array 1: Array ( [0] => Array ( [id] => 1 [name] => Product 1 [quantity] => 2 [unit_amount] => Array ( ...

Convert an array to a string using a JavaScript function

I am encountering an issue with the code below: Every time I pass the Array to "track," I encounter an error. It seems like there might be a mismatch between passing an object and a string as input, but I am uncertain and unable to verify. for (var i = 0; ...

Clear out duplicate elements from array instruction

I am currently working with a div that displays names and I need to remove any duplicates from my array. I have successfully achieved this with a filter, but now I would like to explore creating a directive to extend this functionality. <div ng-control ...

Leverage React.JS to iterate through arrays and objects, rendering data seamlessly - even within nested objects

Development of Category's Filter component Implementing the rendering of data from a nested array using React Js Although I attempted to render it as seen below, it is not displaying anything The main focus is on the rendering part only var selecte ...