Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will need a JavaScript repl to solve parts D1 and D2. D1 JavaScript comparator & custom sorting functions Define a JavaScript comparator function
You will need a JavaScript repl to solve parts D1 and D2. D1 JavaScript comparator & custom sorting functions Define a JavaScript comparator function named rossOrder with 2 parameters. Both parameters will be objects with Numbers for values. Each object will have 3 keys: "points", "goals", and "games". Each object represents an NHL player. Since rossOrder is a comparator function, it must return a Number as follows: a negative value - indicating that the value of the first parameter comes before the value of the second parameter a positive value - indicating that the value of the first parameter comes after the value of the second parameter zero - indicating that the values of the two parameters appear at the same location in the order. To determine how the objects should be ordered, rossOrder should use the following rules (based upon the NHL's Ross Trophy): when the objects have different values for "points", the object with fewer points comes first; when the objects have the same number of points but unequal values for "goals" key, the object with fewer goals comes first; when the objects have equal points and goals, the objects are equivalent. Sample test cases: let mcdavid = {"points": 64, "goals": 22, "games": 43}; let draisaitl= {"points": 64, "goals": 23, "games": 43}; let madeup = {"points": 64, "goals": 22, "games": 45}; rossOrder (mcdavid, madeup) would evaluate to 0 rossOrder (draisaitl, mcdavid) would evaluate to any Number greater than 0 rossOrder (madeup, draisaitl) would evaluate to any Number less than 0 D2. Define a JavaScript custom sorting function named rossTrophy with 1 parameter. This parameter will be an array of objects. The objects will be as described in D1. Your function should result in the array's objects being ordered from the object ranked lowest for the NHL's Ross Trophy to the object ranked highest for the NHL's Ross Trophy (from the smallest to largest points; when objects have equal numbers of points, they are ordered from smallest to largest numbers of goals). Because JavaScript's built-in sort function reorders an array's entries "in place", your rossTrophy function must return undefined. Sample test cases: let nhl = [ {"points": 64, "goals": 22, "games": 43}, {"points": 64, "goals": 23, "games": 43} ]; rossTrophy (nhl) // the order of nhl's entries remains the same. (finds bug if sorting is not done using the built-in in- place function or if sorting is not done by shooting percentage)
Step by Step Solution
★★★★★
3.53 Rating (156 Votes )
There are 3 Steps involved in it
Step: 1
D1 JavaScript Comparator Function rossorder javascript Copy code function rossorderobj1 obj2 if obj1...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started