I would like to know is there any alternative method for a function in my scenario in javascript
Below function works fine, but is there any alternative method to do, since there are more obj
//will get single object as response as anyof these
obj ={"id":"trans", "cn": "SG", "ccy": "SGD"};
obj ={"id": "remit", "cn": "TH", "ccy": "THB"};
obj ={"id": "fund", "cn": "IN", "ccy": "INR"};
function getTrans(){
var value = 1000;
var rate = 0.5;
return value * rate;
}
function getFund(){
var value = 2000;
var rate = 0.2;
return value * rate;
}
var result = getData(obj);
function getData(obj){
if(obj.id==="trans"){
return getTrans(obj);
}
else if(obj.id==="fund"){
return getFund(obj);
}
else{
return obj;
}
}
var objin the code?objthere will be single obj only, will get trans or fund or insta