Skip to content

Latest commit

 

History

History
60 lines (37 loc) · 1.46 KB

File metadata and controls

60 lines (37 loc) · 1.46 KB

Module 3 - Basic Laboratory - Exercise 1 - Array operations

This exercise implements four immutable array operations: head (first element), tail (all except first), init (all except last), and last (last element). Each function uses different JavaScript techniques like destructuring, rest operator, and Array.prototype methods.

Source

Head

Implement an immutable head function that extracts and returns the first element from an array using destructuring.

const head = (/* array */) => {}; // Implementation here.

Tail

Implement an immutable tail function that returns all elements except the first one from an array. Use the rest operator.

const tail = (/* array */) => {}; // Implementation here.

Init

Implement an immutable init function that returns all elements except the last one from an array. Use Array.prototype methods.

const init = (/* array */) => {}; // Implementation here.

Last

Implement an immutable last function that returns the last element from an array.

const last = (/* array */) => {}; // Implementation here.

Installation to develop

  1. Install the Node.js dependencies:

    cd labs-module-3-language/lab-basic/exercise-1
    npm i --save-dev
  2. Start the development server:

    npm run dev
  3. End and happy coding!

Finally

More info in the following commits. If required.

Grettings @jjpeleato.