-
Notifications
You must be signed in to change notification settings - Fork 1
IPW_IP 2122 1 A1
Bachelor in Informatics, Networks and Telecommunications Engineering
Winter Semester of 2021/2022 – 1st practical assignment
NOTE: We expect students to solve Part 1 first, but for Part 2 you will need to request an access id and you should make that request as soon as possible, in order to have the id ready on time for solving Part 2.
Except for classes LEIC52D and LEIC51N, the delivery method is done through Github Classroom, using this invitation link. Following this link, login with your github user and select your student id to make the correspondence between them and so that a private Github repository is created. The assignment should be delivered in this repository, by creating a tag called A1
. If you need to make some amend to the delivery, just create another tag named A1.1
, A1.2
, etc.
Implement and create tests for the following JavaScript functions:
-
filterProperties(propNames,obj)
Receives a string array in
propNames
and an object inobj
. Returns a new object with the properties fromobj
whose names are present inpropNames
. IfpropNames
contains names that do not exist inobj
, those properties are not added to the returned object.Example:
const o = {a: 1, b: 'Thor', c: [1,2,3], d: {x: 10}, e: 2, f: 'Captain America'} const props = ['b', 'd', 'g', 'a'] const oFiltered = filterProperties(props, o) // oFiltered: {a: 1, b: 'Thor', d: {x: 10}}
-
filterPropertiesN(propNames,objs)
Receives a string array in
propNames
and an object array inobjs
. Returns a new object array with objects produced by applying thefilterProperties
function withpropNames
to each object inobjs
.NOTE: In this implementation, the usage of any cycle instruction (for/while) or the
Array.forEach
method reduces the grade in 50%.const objs = [ {a: 1, b: 'Thor', c: [1,2,3], d: {x: 10}, e: 2, f: 'Captain America'}, {b: 'Hulk', a: [1,2,3], d: {x: 10}, e: 2, g: false}, {x: 'Vision', y: false} ] const props = ['b', 'd', 'g', 'a'] const objsFiltered = filterPropertiesN(props, objs) /* objsFiltered: [ {a: 1, b: 'Thor', d: {x: 10}}, {b: 'Hulk', a: [1,2,3], d: {x: 10}, g: false}, { } */
-
Add the
zip(a, combiner)
method to the Array type.The
zip
function receives another array as argumenta
and a combiner function ascombiner
. The combiner function takes two arguments and returns the combination of those arguments. Functionzip
returns an array with every combination of elements at the same position in both arrays (this
anda
). The returned array has the length of the smallest of the combined arrays. Some usage examples of zip function follow:
[1,2,3].zip([4,5,6], function(left, right) { return left + right}) // [5,7,9]
[1,2,3].zip([4,5,6,7,8], (left, right) => left + right) // [5,7,9]
[1,2,3].zip([4,5], (left, right) => left + right) // [5,7]
[1,2,3].zip([], (left, right) => left + right) // []
[].zip([1,2,3], (left, right) => left + right) // []
This part requires that your code makes HTTP requests to the Board Game Atlas API. To access this API, each student must request a token (client_id) that identifies the student application's requests. That token must be included in the URL of each HTTP request. The description of the necessary steps to create the token are described here. Note that this is a free API, and therefore it is expected that you comply to the Rate Limits and Good Citizenship rules.
This application reads game ids from a text file (one per line) and produces a JSON file with an array of objects containing, for each id, an object with the game name and url. For each line an independent HTTP request must be made.
The personal client_id
provided by the Board Game Atlas API, should be left out of the source code and be obtained from an environment variable named ATLAS_CLIENT_ID
.
Implement two versions of the application:
- Using Promises explicitly
- Using the async/await style