JavaScript Higher-Order Functions
Due: 11:00pm, Monday February 22, 2021
Max grace days: 2
Description
The goal for this assignment is to use higher-order functions in JavaScript to process data about Pokemon. The original source of the data for this assignment is here pokemon.json. The data is an array of objects where each object has the following structure:
- “id”: integer
- “name”: Object
- “english”: string
- “japanese”: string
- “type”: Array of strings
- “base”: Object
- “HP”: integer
- “Attack”: integer
- “Defense”: integer
- “Sp. Attack”: integer
- “Sp. Defense”: integer
- “Speed”: integer
This assignment contains the following files: index.html
, data.js
, code.js
, and reference.html
. You only need to edit the code.js
file. You must write five functions where each function has a similar form: take the data (an Array of Pokemon objects) as a parameter and return an Array of Pokemon objects. Descriptions of the functions are as follows:
- Return an array of the five Pokemon objects that have the highest “HP” values. The result must be ordered from highest to lowest “HP” value.
- Return an array of all the Pokemon objects that have the lowest “Sp. Attack” values. The result must be ordered in alphabetic order of English name.
- Return an array of Pokemon objects that have both “Grass” and “Poison” in the “type” property. The result must be ordered from lowest to highest “Attack” value.
- Return an array of Pokemon objects that have “Rock” in the “type” property and also have a “Speed” value higher than the average “Speed” value of Pokemon that have “Electric” in the “type” property. The result must be ordered from highest to lowest “Speed” value.
- Return an array of Pokemon objects where each Pokemon object has an “Attack” value that is at least three times greater than its “Defense” value. The result must be ordered from highest to lowest “Attack” value.
You must also write a “main” function that calls each above function in turn and outputs the results as shown in the reference.html
file. You may also write additional helper functions if you choose to.
All functions in this assignment must satisfy the following criteria:
- cannot mutate the original
data
array, - cannot contain
for
orwhile
loops, - any call to the
Array.sort
function must include the optional second argument (a comparison function.)
Turning in the Assignment
For this assignment, you must turn in a zip file containing the following file:
code.js
Submit the zip file to the appropriate folder on D2L.
Grading Criteria
Grading (out of 100 points):
- 10 points – Documentation
- 10 – complete documentation that follows the standards
- 5 points – incomplete documentation and/or documentation that does not follow the standards
- 0 points – no documentation
- 90 points (15 points per function) – Implementation
- 90 points – correct implementation
- 45 points – partially correct implementation
- 0 points – incorrect implementation