Chapter 5: Functional Programming
Activity 1 – Recursive Immutability
You are building an application in JavaScript and your team has been told that it cannot use any third-party libraries for security reasons. You must now use Functional Programming (FP) principles for this application and you need an algorithm to create immutable objects and arrays. Create a recursive function that enforces the immutability of objects and arrays at all levels of nesting with Object.freeze(). For simplicity, you can assume that there are no null or classes nested in the objects. Write your function in activities/activity5/activity-test.js. This file contains code to test your implementation.
To demonstrate forcing immutability in objects, follow these steps:
- Open the activity test file at
activities/activity5/activity-test.js. - Create a function called
immutablethat takes in a single argument,data. - Check to see if
datais not of typeobject. If it is not, then return...