- This coding challenge solves a very interesting algorithmic problem known as Lazy Evaluation. It has two ways of solving the problems, one with mutable instance, and another with immutable instance. To know more, feel free to check the following code files:
- Lazy evaluation is an evaluation strategy which delays the evaluation of an expression until its value is needed.
- JavaScript - Programming language Used to create this project
- Jest - For Unit Test Cases.
- Have
node
andnpm
installed in your system
- Please run
npm install
to first install all the dependencies to be able to successfully run the project (if you'd like to run the test and see the testcases passing based upon the conditions provided).- Please confirm whether you have node installed in your system by running
node -v
andnpm -v
.
- Please confirm whether you have node installed in your system by running
- To run the file simply go inside the directory
main
in your terminal and do nodeevaluateLazy.js
. Please make sure to uncomment the code in the last to see the results. - [Optional and depenedent on the first point] To run the test simply in the root directory run this command
npm run test
.
- Output will be in a format of Array of Integers with the length of the
evaluate
argument array provided, which is below:
[3, 5, 7];
- For successfull unit test cases running, this will be the output:
PASS main/evaluateLazy.test.js
...
Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: 0.22 s, estimated 1 s
Ran all test suites.
- For failure unit test cases, this will be the output:
Lazy › returns a data when no argument is passed for inbuilt method
...
Test Suites: 1 failed, 1 total
Tests: 1 failed, 5 passed, 6 total
Snapshots: 0 total
Time: 0.31 s, estimated 1 s
Ran all test suites.
-
target
argument will always be an array and cannot be provided as number/integer toevaluate
. As the statement in the project guideline mentioned it clearly: When the function is called it will be called with the remaining arguments supplied to add (if any) followed by a single argument that will be an item from the target array supplied to evaluate. -
There is no need of handling the edge cases ofr
evaluate
andadd()
args, following the documents statement: Don't be defensive about the degenerate cases (E.g. bad / missing arguments). -
[Mentioned in the problem document]
add
was called at least once (i.e. don't account for the case where the Lazy instance had no functions added to it). -
The
add()
functional arguments will always receive the integer/number constant arguments for the first nth arguments provided in theadd()
followed by theevaluation
constant value picked from the argumenttarget
(the below code example gave the assumptions source)
add(plus(a, b) { return a + b; }, 1) // a plus function that will be given 1 as its first argument