Giter Club home page Giter Club logo

ib-homeworkstarter's Introduction

Homework Assignment

This assignment covers the first week of the Intermediate Bootcamp. This repository contains 3 test files, each covering a single task. The order of the tasks does not matter. You can complete them in any order. Try to complete as many of them as you can.

First run npm install to install the dependencies. Run the tests with the command npm test. Read the instructions in this document to know what is expected of you. The tests are meant to help and guide you. Passing tests do NOT automatically mean a successful implementation. Again, tests do not equal score! You can read the tests to see exactly what it's expecting, especially if you're getting errors. However, do not change the tests.

Make sure to hand in the project the way you received it! The tests should still work and be runnable with the npm test command after you hand in your homework.

You can also run the tests for each assignment individually by executing npm run test1, npm run test2 and npm run test3.

If you want to play around with your code yourself (not using the provided tests), here's a tip. Instead of adding test code to your solution files, create a new .js file and run it with node.

Note: we'll use the results of this homework assignment for a formal evaluation and as such you should write the code individually. Plagiarism is a violation of the Academy contract and is not in your best interest. Do not discuss the contents of the assignment with your fellow students.

How to submit your results

Send your homework to [email protected] before Saturday 22:00

Clean up your code:

  • Fix the formatting/indentation
  • Remove unnecessary code.

The app should be runnable simply by cloning the repository, installing dependencies, and running npm test.

Instructions

Assignment 1: ShoppingCart

  1. You must create a module named ShoppingCart. The module must export a class! In other words your module.exports is not an object, a string, or anything else, but only a class.
  2. Given a brand new instance of the class in a variable cart, calling cart.getItems() should return an empty array.
  3. The class should have a method cart.addItem(itemName, quantity, price), which adds a new item to an internal array.
  4. After adding items, a call to cart.getItems() should return an array that includes the added items.
  5. Items in the array should be in this format:
    {
      name: "Name of the item",
      quantity: 1,
      pricePerUnit: 99.99
    }
  6. Calling cart.clear() should remove all items from the items array. Meaning, the next call to getItems() should return an empty array.
  7. Calling cart.total() should return the total value of the shopping cart. Meaning, the sum of the cost of each cart item. The cost of each item is its pricePerUnit multiplied by the quantity. Use reduce!

Assignment 2: transform

  1. You must create a module named transform that exports a function named groupAdultsByAgeRange. The test imports it like this:
    const groupAdultsByAgeRange = require("./transform").groupAdultsByAgeRange
    Note: This is a named export
  2. The exported groupAdultsByAgeRange should be a function.
  3. The function will be called with an array of objects as its argument. The objects represent people, with a property name and a property age. Your function should group each person over the age of 18 into age ranges. Here are a few examples:
    // Example 1
    groupAdultsByAgeRange([{name: "Henry", age: 9}, {name: "John", age: 20}])
    // Should result in:
    const result = { '20 and younger': [ { name: 'John', age: 20 } ] }
    
    // Example 2
    groupAdultsByAgeRange([{name: "Anna", age: 31}, {name: "John", age: 32}, {name: "Hank", age: 60}])
    // Should result in:
    const result2 = { 
      '31-40': [ { name: 'Anna', age: 31 }, { name: 'John', age: 32 } ],
      '51 and older': [ { name: 'Hank', age: 60 } ] 
    }
  4. Notice that the groups are only added to the resulting object if they are not empty. Make sure your function does the same.
  5. You should use a combination of filter and reduce. If your solution uses for-loops instead of reduce for creating the final object, you will receive partial points. The use of for-loops is allowed, but try to construct the returned "grouping" object using reduce.
  6. These are the groups that your code needs to return. Use the text as the name of the property:
    • 20 and younger
    • 21-30
    • 31-40
    • 41-50
    • 51 and older

Assignment 3: Asynchronous code

  1. You must create a module named async-functions. The test imports it with

    const {
      getTatooineResidents,
    } = require("./async-functions")

    _Note: There should be 1 named export it should be a function

  2. The function getTatooineResidents

  • Makes a request to the starwars api endpoint: https://swapi.co/api/planets/1/ to get info about the planet Tatooine
  • Feel free to use npm to install a http client like superagent to make the request
  • Making a request with superagent should create a Promise, return that promise from the function getTatooineResidents
  • Add a then() block to the promise you return from getTatooineResidents
  • return an array of urls for the residents of Tatooine (not the whole response) from the last .then() block in the promise chain

ib-homeworkstarter's People

Contributors

bramkoot avatar reinoptland avatar mimimag avatar

Watchers

Kelley van Evert avatar Wouter de Vos avatar  avatar James Cloos avatar Johan Kruse avatar Arien Kock avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.