Please explain what this code is doing step by step and how to get the answer of a= 6 , b = 11
const inc = x => x+1;
const dub = x => x+x;
const U =2;
const V =5;
const LR = (x,f) => f(x);
const RL = (f,x) => f(x);
const a = RL(dub, LR(U, inc));
const b = LR(RL(dub,V), inc);
a = 6
b= 11
Each step is numbered and commented for better understanding.
1. const inc = x => x+1; //inc is a function that inputs x
and outputs x+1
2. const dub = x => x+x;. //dub is a function which inputs x and
outputs the double value of x
3. const U =2; . // A const variable U with value assigned
2
4. const V =5; . //A constant variable V with value assigned
5
5. const LR = (x,f) => f(x); . //Function with X and a function
as inputs and outputs the function with input as x
6. const RL = (f,x) => f(x);. //Function which will output
according to the input X and the input function
7. const a = RL(dub, LR(U, inc)); //the step by step procedure can
be implemented for this step as, RL(dub,LR(2,inc)) which results in
RL(dub,3) which returns a=6.
8. const b = LR(RL(dub,V), inc); // likewise above, LR(10,inc) will
yield b=11
Get Answers For Free
Most questions answered within 1 hours.