dev2 – 10 advanced array methods problem set

Using the included array of objects, create the requested functions using the named array methods in following JS file. Below is the contents of the JS file in a code snippet. Upload to your server the completed problem set HTML/JS adv-array.html / adv-arr.js pair and link them in your course post for the week.

var students = [{
        name: "Diksha Dohman",
        age: 20,
        major: "Communications Technology",
        coursesTaken: ["CT 101", "CT 210", "CT 137", "CT 205"],
        totalCredits: 75,
        enrolled: true
    },
    {
        name: "Voski Dreher",
        age: 24,
        major: "Communications Technology",
        coursesTaken: ["CT 101", "CT 160", "CT 201", "CT 210", "CT 137", "CT 205", "CT 240", "CT 355", "CT 345"],
        totalCredits: 110,
        enrolled: true
    },
    {
        name: "Divya Glas",
        age: 19,
        major: "Communications Technology",
        coursesTaken: ["CT 101"],
        totalCredits: 15,
        enrolled: false
    },
    {
        name: "Theofanis Sandoval",
        age: 20,
        major: "Communications Technology",
        coursesTaken: ["CT 101", "CT 201", "CT 137", "CT 160", "CT 360", "CT 370", "CT 381", "CT 385"],
        totalCredits: 95,
        enrolled: true
    },
    {
        name: "Wolf Shepard",
        age: 21,
        major: "Communications Technology",
        coursesTaken: ["CT 101", "CT 201", "CT 137", "CT 160", "CT 360"],
        totalCredits: 45,
        enrolled: false
    }
]


// Write a function courseCount(studArr) that takes an array as an argument and uses a forEach method to count the number of courses a student has taken. Console.log the student's name and the number of courses taken by the student.

//For example the last console.log would be
//"Wolf Shepard has taken 5 courses."

function courseCount(studArr) {

}

//Write a function firstLast(studArr) that uses a map method to return an array of objects with added first and last keys with the first and last names created from the name value.

//For example the last object in the array would now include:

//first: "Wolf"
//last: "Shepard"

function firstLast(studArr) {

}

//Write a function isEnrolled(studArr, bool) which takes an array and a boolean value as arguments. Use the filter method to check which students are or are not enrolled. Returns an array of student objects.

function isEnrolled(studArr, bool) {

}

//Write a function courseCompleted(studArr, courseNum, bool) that takes an array, the string value of a course number, and a Boolean value. 
//Use a reduce() method to return an array of objects with the students that have taken or not taken the particular course.
//return in each object the name of the student, and two new key value pairs – course: courseNum and taken: bool

//Example returned object in array of objects
// {
//     name: "Wolf Shepard",
//     course: "CT 101",
//     taken: true
// }

function courseCompleted(studArr, courseNum, bool) {

}

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

css.php