Question: Write a function that receives a key - value pair ( for example: ( 3 . 5 : 4 8 1 ) where the key

Write a function that receives a key-value pair (for example: (3.5: 481) where the key (in this case: 3.5) is the note and the value (in this case: 40) is the percentage of the respective note. The function returns an object with two properties:
accumulated Percentage equal to the sum of all percantages (values)
accumulatedNote equal to the sum of products of each note and its corresponding percentage (key-value pairs) Make sure that the input entered is fully correct with the validations needed.
Hints
Since the notes and percentages are entered in an object, the notes (keys) must all be different. You can use console.log to debug the output from your solution.
Requirements
The function accepts an object that cannot be empty. Arrays are not allowed.
Keys or values that are null, undefined or empty are not allowed.
A key must be a number in the range [0,5](0<= key <=5).
A value must be an integer number in the range (0,100](0< value <=100).
The total sum of percentage values must be a maximum of 100.
Output is an object that contains accumulatedPercentage and accumulatedNote properties. In some particular cases (described in section below) an error message should be thrown.
Examples
Case 1: Output is an object that contains accumulatedPercentage and accumulatedNote properties.
Input: academicNotes (2.9: 48,3.1: 30))
Expected Output: (object as example){ accumulatedPercentage: 70, accumulatedNote: 2.09
Case 2: Input is not an object (arrays are not allowed).
Input: academicNotes (12.9: 4011)
Expected output: throws an error with message Not an object
Case 3: Input is an empty object.
R
Input: academicNotes({})
Expected Output: throws an error with message Object is empty.
Case 4: Input has some null, undefined, empty or not a number as key. For the
Input: academicNotes ((2.9: 48, null: 30) or academicNotes({ undefined: 40,3.1: 381) or academicNotes({2.9: 40,30) or academicNotes({'2.9x: 48,3.1:
38})
Expected Output: throws an error with message Some key is not a number
Case 5: Input has some key that is out of range.
Input: academicNotes({2.9: 48,3.1': 30))
Expected Output: throws an error with message 'Some key is out of range
Case 6: Input has some null, undefined, empty or not a integer as value.
Input: academicNotes({2.9: null, 3.1: 30)) or academicNotes (2.9: 40,3.1: undefined) or academicNotes (12.9:,3.1: 38}) or academicNotes({2.9: 40,3.1: 30x') or academicNotes((2.9: 40.1,3.1: 38))
Expected Output: throws an error with message 'Some key is not an integer'
Case 7: Input has some value out of range.
Input: academicNotes({2.9: 40,3.1: -30))
Expected Output: throws an error with message 'Some value is out of range
Case 8: Input has values that exceed the maximum sum.
Input: academicNotes (12.9: 71,3.1: 30))
Expected Output: throws an error with message Total sum of percentage values exceeds the maximum
Environment
Node 14

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!