Skip to content

Commit

Permalink
Remove ratings that were found
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Apr 15, 2023
1 parent ff95523 commit 61ef409
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions extensions/yourViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ const sameOrder = (
productIds: readonly string[],
elements: Rating[],
): (Rating | undefined)[] => {
const ordered = new Array<Rating | undefined>(productIds.length);
const ordered = new Array<Rating | undefined>(productIds.length).fill(
undefined,
);
for (let i = 0; i < productIds.length; i++) {
ordered[i] = elements.find((e) => e.ProductId === productIds[i]);
const ratingIdx = elements.findIndex((e) => e.ProductId === productIds[i]);
if (ratingIdx !== -1) {
ordered[i] = elements[ratingIdx];
elements.splice(ratingIdx, 1); // remove already found rating
}
}
return ordered;
};

0 comments on commit 61ef409

Please sign in to comment.