I want to know if we can call an extern function/method inside reduce iteration ?
Inside mainFunction i'm using reduce on array and i want to call an extern function formatDate inside my reduce iteration, is this good approach to do it ? if yes then how ?
private mainFunction() : {
let v_arrayGroup:string[]=[];
myArray.reduce(function (res, value) {
let v_key = value.firstVar;
if (!res[v_key]) {
res[v_key] = {
firstVar: value.firstVar,
NbrKo: 0,
sndVar: this.formatDate(value.sndVar)
};
v_arrayGroup.push(res[v_key]);
}
res[v_key].NbrKo++;
return res;
}, {});
v_finalArray = v_arrayGroup;
}
private formatDate=(p_date:Date)=> {
let addZeroToLoneFigure = (n) => n.toString().length === 1 ? '0' + n : n.toString();
let _dateReturn = 'DD/MM/YYYY';
_dateReturn= _dateReturn.replace("DD", addZeroToLoneFigure(p_date.getDate()));
_dateReturn= _dateReturn.replace("MM", addZeroToLoneFigure(p_date.getMonth() + 1));
_dateReturn= _dateReturn.replace("YYYY", addZeroToLoneFigure(p_date.getFullYear()));
return _dateReturn;
}