Skip to content

Commit

Permalink
Fix sorting duplication bug Part1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-Sdg90 committed Apr 12, 2024
1 parent ce17be1 commit 9ccdab8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion JS/interfaceClass.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion JS/interfaceClass.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion JS/sortSection.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion JS/sortSection.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion TS/interfaceClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Items implements Iitem {
<div class="item-box">
<img class="item-image" src="${this.image}" alt="item-image" />
<div class="item-title" title=${this.title}>${this.title}</div>
<div class="item-title" title="${this.title}">${this.title}</div>
<div class="item-info">
<div class="item-price">${this.price} $</div>
Expand Down
28 changes: 24 additions & 4 deletions TS/sortSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,31 @@ const sortItemsFunc = (
}
});
});
// console.log("sortedItems >>", sortedItems);
console.log("sortedItems >>", sortedItems);

const sortedItemOutputs = sortedItems.map((sortedCard) =>
sortedCard[0].createCard()
);
const addedIDs: number[] = [];

const sortedItemOutputs = sortedItems.map((sortedCards) => {
let uniqueCard = sortedCards[0];

console.log("Before", addedIDs);

sortedCards.map((sortedCard) => {
if (!addedIDs.includes(sortedCard.id)) {
addedIDs.push(sortedCard.id);

console.log("After", addedIDs);

uniqueCard = sortedCard;
return;
}
});

console.log("uniqueCard >>", uniqueCard);

return uniqueCard.createCard();
// return uniqueCard;
});
// console.log("sortedItemOutputs >>", sortedItemOutputs);

itemSection.innerHTML = "";
Expand Down

0 comments on commit 9ccdab8

Please sign in to comment.