function customSort()

in read_input/util.js [312:333]


function customSort(arr, orderMap) {
  arr.sort((a, b) => {
    const indexA = orderMap[a];
    const indexB = orderMap[b];

    // Handle cases where elements are not in the custom order
    if (indexA === undefined && indexB === undefined) {
      // If both elements are not in the orderlist, keep as it is
      return 0;
    } else if (indexA === undefined) {
      // If a is not in the orderlist, place it after b
      return 1;
    } else if (indexB === undefined) {
      // If b is not in the orderlist, place it after a
      return -1;
    } else {
      // If both elements are in the order, sort by their indices
      return indexA - indexB;
    }
  });
  return arr;
}