I was asked in an interview to solve
init(1).add(2).mul(3).div(4).val();
Output it should achieve this functionality, I am more concerned about how to call in the above way
(1 + 2) * 3 / 4 = 2.25
How can we implement it using javascript? I thought of creating functions with nested function, whats the correct way?
I did
var gmap = function(num) {
this.x = num;
this.add = function(ad) {
this.x = this.x * ad;
return this;
}
this.del = function(de) {
this.x = this.x + de;
return this;
}
this.final = function() {
return this.x;
}
}