Privacy about Project: what to see, what you can modify...

This commit is contained in:
Paolo Arena
2019-04-20 13:59:07 +02:00
parent 6a0b7db73c
commit e0e48f7eb2
3 changed files with 118 additions and 28 deletions

View File

@@ -200,7 +200,8 @@ module.exports = {
// SORT WITH PREV_ID
// **********************
mapSort: function (linkedList) {
var sortedList = [];
let sortedList = [];
let remainingList = [];
var map = new Map();
var currentId = null;
@@ -219,21 +220,30 @@ module.exports = {
}
}
while (sortedList.length < linkedList.length) {
let conta = 0;
while (conta < linkedList.length) {
// get the item with a previous item ID referencing the current item
var nextItem = linkedList[map.get(currentId)];
if (nextItem === undefined) {
break;
} else {
sortedList.push(nextItem);
currentId = String(nextItem._id);
}
sortedList.push(nextItem);
currentId = String(nextItem._id);
conta++;
}
if (sortedList.length < linkedList.length) {
if (linkedList.length > sortedList.length) {
// If are not in the list, I'll put at the bottom of the list
console.log('ATTENZIONE !!! ', sortedList.length, linkedList.length);
for (const itemlinked of linkedList) {
const elemtrov = sortedList.find((item) => item._id === itemlinked._id);
if (elemtrov === undefined) {
sortedList.push(itemlinked);
}
}
}
// console.log('DOPO sortedList', sortedList);
return sortedList;