Question: In the following code using the list abstract data type, A and B are constants. function prepend ( e , lst ) { return lst

In the following code using the list abstract data type, A and B are constants.
function prepend(e, lst){ return lst = node(e, lst); }
const sum = lst => lst.isEmpty()?0 : lst.head()+ sum(lst.tail());
let lst1= node(A, node(B, empty()));
prepend(A, lst1);
let lst2= prepend(B, lst1);
console.log(sum(lst1));
console.log(sum(lst2));
If the two numbers printed are 8 and 4, what is the value of A?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!

Q:

19