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.
Implement an immutable head function that extracts and returns the first element from an array using destructuring.
const head = (/* array */) => {}; // Implementation here.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.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.Implement an immutable last function that returns the last element from an array.
const last = (/* array */) => {}; // Implementation here.-
Install the Node.js dependencies:
cd labs-module-3-language/lab-basic/exercise-1 npm i --save-dev -
Start the development server:
npm run dev
-
End and happy coding!
More info in the following commits. If required.
Grettings @jjpeleato.