Skip to content

IPW_IP 2122 1 A1

Luís Falcão edited this page Oct 20, 2021 · 2 revisions
Instituto Superior de Engenharia de Lisboa
Bachelor in Computer Science and Computer Engineering
Bachelor in Informatics, Networks and Telecommunications Engineering
Internet Programming/Introduction to Web Programming

Winter Semester of 2021/2022 – 1st practical assignment


Delivery

Due date for this assignment: 08/11/2021-23h59.

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.

Delivery method

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.

Part 1 - JavaScript functions

Implement and create tests for the following JavaScript functions:

  1. filterProperties(propNames,obj)

    Receives a string array in propNames and an object in obj. Returns a new object with the properties from obj whose names are present in propNames. If propNames contains names that do not exist in obj, 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}}
  2. filterPropertiesN(propNames,objs)

    Receives a string array in propNames and an object array in objs. Returns a new object array with objects produced by applying the filterProperties function with propNames to each object in objs.

    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}, 
       { }
    */
  3. Add the zip(a, combiner) method to the Array type.

    The zip function receives another array as argument a and a combiner function as combiner. The combiner function takes two arguments and returns the combination of those arguments. Function zip returns an array with every combination of elements at the same position in both arrays (this and a). 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) // []

Part 2 - Node application

Foreword

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.

Application requirements

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:

  1. Using Promises explicitly
  2. Using the async/await style