Skip to content

Workshop to learn basic functional programming in JavaScript.

Notifications You must be signed in to change notification settings

alvinberthelot/workshop-functional-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

workshop-functional-js

Workshop to learn basic functional programming in JavaScript.

Commands

Installation

Please install dependencies first.

npm install

Tests & lint

To launch the tests.

npm test

To lint sources.

npm run lint

Start

To start program.

npm start

Exercises

Please verify that after all exercises the linter should not return errors.

Exercise 1

Write a simple test in file test/program.test.js to verify that the parameter is mutated with the function transformCheckpoint in file src/program.js.

👉 function .eql from Chai should help you.

You could use this example data to run your test :

{
  id: 'whataw0nd3rful1d',
  uuid: 'whataw0nd3rful1d',
  address: 'unknown',
  addressType: 'unknown',
  connectable: true,
  advertisement: {
    localName: undefined,
    txPowerLevel: undefined,
    manufacturerData: undefined,
    serviceData: [],
    serviceUuids: [ 'abcd' ]
  },
  rssi: -66,
  services: null,
  state: 'outofcontrol'
}

After finish this exercise, please commit all your files.

git add .

git commit -m "Exercise 1"

Exercise 2

  1. The function transformCheckpoint in file src/program.js is so impure, please change it to become a pure function.

  2. Update test created in exercise 1 if necessary.

  3. Write a test to be sure that output has a different reference than input.

👉 function .cloneDeep from Lodash should help you.

👉 function .equal from Chai should help you.

Please make all tests pass.

After finish this exercise, please commit all your files.

git add .

git commit -m "Exercise 2"

Exercise 3

Our program is better because we use more pure functions, but now the display in our CLI (Command Line Interface) is different than before when we use :

npm start

Please update the function run in file src/program.js.

  1. The display in CLI should be the same than before.

  2. Use methods from Array.prototype to do it in a functional programming way.

Please make all tests pass.

After finish this exercise, please commit all your files.

git add .

git commit -m "Exercise 3"

Exercise 4

Now we want to use Lodash to manipulate object (as a collection) in a functionnal programming way.

Use simple Lodash functions to refactor function showCheckpoint in file src/program.js, especially the for loop.

Please make all tests pass.

After finish this exercise, please commit all your files.

git add .

git commit -m "Exercise 4"

Exercise 5

With Lodash we want to facilitate the visualization of the calculate property "distance" for all the checkpoints.

  • We want to add an unit for the distances, add "m" for distances greater or equal than 1, otherwise add "cm" and multiply by 100. For examples 1.25 should display "1.25 m" and 0.72 should display "72 cm".

  • We want to round calculate property "distance" with a precision of 2 decimals. For examples 0.3421673604634194 should become 0.34 or 10.467388920465797 should become 10.47.

  • We want to sort checkpoints with calculate property "distance" in an ascending way.

Implement theses new features and be careful with the order to apply them.

Please make all tests pass.

After finish this exercise, please commit all your files.

git add .

git commit -m "Exercise 5"

About

Workshop to learn basic functional programming in JavaScript.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published