Last active
December 27, 2023 02:19
-
-
Save the-glima/58315cfc94fc0ef5cbd162996b904cf8 to your computer and use it in GitHub Desktop.
Liga finding duplicates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find Duplicate Cards | |
var cards = $('.cardtitle').toArray() | |
var cardTitles = cards.map(c => c.innerText) | |
var toFindDuplicates = array => array.filter((item, index) => array.indexOf(item) !== index) | |
var duplicateElements = toFindDuplicates(cardTitles); | |
var findDiff = (array, array2) => array.filter(i => !array2.includes(i)); | |
// Log Duplicates | |
if (!duplicateElements.length) { | |
console.log("%c1. No duplicates, all good!", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%c1. Found some duplicate cards", "color:red; font-size: 18px"); | |
duplicateElements.forEach(item => console.log(item)) | |
console.log('') | |
} | |
// Log quantities above 1 | |
var qty = $('.qty').toArray() | |
var qtyValues = qty.map(q => q.value) | |
var values = qty.filter(q => q.value !== '1') | |
if (!values.length) { | |
console.log("%c2. No quantity above 1", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%c2. Found a card with quantity above 1", "color:orange; font-size: 18px"); | |
var result = values.map(i => i.closest('.row').querySelector('.cardtitle')) | |
result.forEach(item => console.log(item.innerText, item)) | |
console.log('') | |
} | |
// Log comparison with custom list | |
var customList = [] | |
var dupsInCustomList = toFindDuplicates(customList) | |
if (!dupsInCustomList.length) { | |
console.log("%c3. No duplicate in custom list", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%c3. Found some dupes in custom list", "color:red; font-size: 18px"); | |
dupsInCustomList.forEach(item => console.log(item)) | |
console.log('') | |
} | |
var foundCustomDup = cardTitles.filter(c => { | |
var result = customList.some(p => { | |
if (c.match(new RegExp(p, 'ig'))) { | |
return !!c.match(new RegExp(p, 'ig')).filter((str) => str !== '').length | |
} | |
}) | |
if (result) return c | |
}) | |
if (!foundCustomDup.length) { | |
console.log("%c4. No duplicate from shopping list and custom list", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%c4. Found some dupes from shopping list and custom list", "color:red; font-size: 18px"); | |
[...new Set(foundCustomDup)].forEach(item => console.log(item)) | |
console.log('') | |
} | |
// Log missing cards in custom list | |
var missingCustomList = [] | |
var diffInCustomList = findDiff(missingCustomList, cardTitles) | |
if (!diffInCustomList.length) { | |
console.log("%c5. No missing cards from custom list", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%c5. Found some missing cards in custom list", "color:red; font-size: 18px"); | |
diffInCustomList.forEach(item => console.log(item)) | |
console.log('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment