JavaScript exercises

Find associated code in the corresponding repositories at https://github.com/1dv021

Before you start:

  1. Open a terminal
  2. git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi'
  3. Change to the (git initialized) directory for tasks
  4. git remote add hello-world https://github.com/1dv021/exercise-hello-world.git
  5. git remote -v
  6. git subtree add --prefix=hello-world --squash hello-world master
  7. git ignore node, visualstudiocode (or a better IDE), linux (or a worse OS) >> .gitignore
  8. git add .
  9. git commit -m 'Adding .gitignore'
  10. git push
  11. Start coding and make frequent commits.

Part 1

A-level

Hello, World!

Make a function that returns the text 'Hello, World!'

Make the function testable with npm:
describe('hello module', () => {
  describe('#sayHello()', () => {
    it('should return \'Hello, World!\'', () => {
      expect(hello.sayHello()).to.eql('Hello, World!')
    })
  })
})

Simple addition

Pre tiny funcs

Tiny funcs

Right triangle

Print a triangle with #'s.

Data type determinator

Print the type of the argument.

Shaver sharp html

Additional array copy

let newArray = ma.immutablePushNumber(arr, 4);

Sorted array copy

Sorting objects

Sort array of objects

B-level

Bugsy

Search names from initials using generator objects.

Better than average

Filter an array of objects. Consider Array.reduce, Array.filter and Array.map.

Reduced array

Get sum with Array.reduce.

C-level

Abacus

Adder that accepts variable number of arguments directly as numbers or parsed from strings. Optionally add support for nested arrays.

Useful concepts: arguments object , spread syntax , Array.concat, Array.some, String.indexOf, String.replace

Harshad number

Find numbers evenly divisible by the sum of their digits: 24 since 24/(2+4)=4

Useful functions: Number.toString, String.split, parseInt.

Reduced array of objects

Get sum with Array.reduce.

The best of the best

Count frequencies of names in a list.

Useful functions: Array.every, Array.filter

Part 2

A-level

Lego maker

Explore the factory, constructor (also with prototype) and class patterns.

Constructive prototype of ellipse

Make a constructor/prototype pattern for ellipses and one for circles through inheritance.

New classic ellipse

As above except with class syntax.

Examinations

Task 1: Descriptive statistics

https://github.com/1dv021/examination-1

JSDOC comment:
/**
* Returns the descriptive information (maximum, mean, median, minimum, mode, range and standard deviation) from a set of numbers.
*
* @param {number[]} source The set of data to be analyzed.
* @throws {TypeError} The passed argument is not an array.
* @throws {Error} The passed array contains no elements.
* @throws {TypeError} The passed array contains not just numbers.
* @returns {{maximum: number, mean: number, median: number, minimum: number, mode: number[], range: number, standardDeviation: number}}
*/
Document your own functions too.

Task 2: Twenty one

https://github.com/1dv021/examination-2

Note: This is not black jack, however if you aren't doing the formal examination feel free to implement the classical black jack game.




Updated on 2020-08-07.