Privacy about Project: what to see, what you can modify...
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user