Trying to write logic if object path are same it should create one object in the array with name comma separated, How to use reduce to achieve this task ?
main.js
var data = [
{id: "param", name: "IGetRefillMultiPlanParam", path: "@combinator-interfaces/dist/drug/GetRefills/GetRefills.Model.ts"}
{id: "details", name: "IRefills", path: "@combinator-interfaces/dist/drug/GetRefills/GetRefills.Model.ts"}
{id: "header", name: "IHeader", path: "@combinator-interfaces/dist/common/Header.Model.ts"}
]
function buildInterface (data) {
var interfaceArray = [];
data.reduce(function(acc,arr){
var filePath = acc.path.replace('.ts','');
var imports = data.map(d => d.name).join(', ');
if(acc.path.includes(arr.path)) {
interfaceArray.push(`import { ${imports} } from '${filePath}';\n\n`);
}
});
return interfaceArray;
}
Expected Result
[
'import { IGetRefillMultiPlanParam, IRefills} from "@combinator-interfaces/dist/drug/GetRefills/GetRefills.Model"',
'import { IHeader } from "@combinator-interfaces/dist/common/Header.Model"'
]
i Uncaught TypeError: Cannot read property 'path' of undefinedreduceyet. Also, can you explain your algorithm in English? What exactly are you trying to do?