Skip to content

Commit

Permalink
Fix error coming from empty array reduce call
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex authored and ilayaperumalg committed Sep 6, 2019
1 parent f592525 commit 6a2cd7d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions ui/src/app/streams/components/flo/text-to-graph.ts
Expand Up @@ -284,7 +284,7 @@ export class TextToGraphConverter {
}

private matchGroup(name: string, incoming: number, outgoing: number): string {
const match1 = Array.from(this.metamodel.keys()).filter(grp => this.metamodel.get(grp).has(name)).map(
const matches = Array.from(this.metamodel.keys()).filter(grp => this.metamodel.get(grp).has(name)).map(
grp => this.metamodel.get(grp).get(name)).map(match => {
let score = 0;
switch (match.group) {
Expand Down Expand Up @@ -336,15 +336,21 @@ export class TextToGraphConverter {
match,
score
};
}).reduce((bestMatch, currentMatch) => {
if (bestMatch) {
if (currentMatch.score > bestMatch.score) {
return currentMatch;
});
if (matches && matches.length > 0) {
const match1 = matches.reduce((bestMatch, currentMatch) => {
if (bestMatch) {
if (currentMatch.score > bestMatch.score) {
return currentMatch;
}
}
return bestMatch;
});
if (match1) {
return match1.match.group;
}
return bestMatch;
});
return match1 ? match1.match.group : ApplicationType[ApplicationType.app];
}
return ApplicationType[ApplicationType.app];
}

/**
Expand Down

0 comments on commit 6a2cd7d

Please sign in to comment.