Skip to content

Instantly share code, notes, and snippets.

@kdssoftware
Last active October 26, 2020 09:38
Show Gist options
  • Save kdssoftware/4a30eefb4460ca3bff925d79d9542fa0 to your computer and use it in GitHub Desktop.
Save kdssoftware/4a30eefb4460ca3bff925d79d9542fa0 to your computer and use it in GitHub Desktop.
finds duplicate items of self defining properties
//finds duplicate items of self defining properties, returns [{item1,item1duplicate},{item2,item2duplicate},{...}]
function (e, data){
const itemList = JSON.parse(data);
let data = [];
let currentIndexForData = 0;
itemList.data.forEach(
(item,index)=>{
let addedToDataThisCycle = false;
let addedThisItemToDataThisCycle = false;
//current item, will check if any other item (exluding self) is same, add to data if so
console.clear();
console.log("Loading... "+(index/(itemList.data.length/100.0)).toFixed(2)+'%');
itemList.data.forEach(
(comparingItem)=>{
if(item.inventory_id!==comparingItem.inventory_id){ //exclude self
if(isDuplicate(item,comparingItem)){
let itemNotYetUsedAsComparingItem = true;
//check if comparingItem already was an Item
data.data.forEach((dataOfData)=>{
dataOfData.forEach((checkItem)=>{
if(isDuplicate(item,checkItem)){
itemNotYetUsedAsComparingItem=false;
}
});
});
if(itemNotYetUsedAsComparingItem){
//if almost the same item, add this item to a new array in data array(data)
addedToDataThisCycle = true;
if(!addedThisItemToDataThisCycle){
data.data.push([item]);
addedThisItemToDataThisCycle=true;
}
data.data[currentIndexForData].push(comparingItem);
}
}
}
}
);
//next item in inventory list
if(addedToDataThisCycle){
//if something has been added to the data, the currentIndex will be changed
currentIndexForData++;
}
}
);
return data;
});
// list the properties that will check if it is in fact duplicate.
//in example: 4 properties
function isDuplicate (item,checkItem){
return item.item.no===checkItem.item.no && item.new_or_used===checkItem.new_or_used && item.color_id===checkItem.color_id && item.description===checkItem.description;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment