64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
// arrayは現在位置の駅ID(駅在宅の場合は1つの配列、駅間の場合は2つの配列)
|
|
// stopStationIDListは停車駅の駅IDの配列 [Y01,Y02,Y05,...]
|
|
export const findReversalPoints = (array, stopStationIDList) => {
|
|
try {
|
|
if (!stopStationIDList) return [];
|
|
// arrayが二次元配列だったら早期リターン
|
|
if (!array instanceof Array) return [];
|
|
if (!array) return [];
|
|
if (array[0] instanceof Array) return [];
|
|
|
|
// 完全一致
|
|
if (array.length == 1) {
|
|
const index = stopStationIDList.map((d) => {
|
|
let a = false;
|
|
d.forEach((x) => {
|
|
if (x == array[0]) a = true;
|
|
});
|
|
return a;
|
|
});
|
|
if (index != -1) return index;
|
|
}
|
|
// 駅間の場合
|
|
if (array.length == 2) {
|
|
const allThroughStation = stopStationIDList.map((d, index, arrays) => {
|
|
if (array[0] == "Y09" && array[1] == "M12") {
|
|
return d[0] == "M12" ? true : false;
|
|
} else if (array[0] == "M12" && array[1] == "Y09") {
|
|
if (index) {
|
|
if (arrays[index - 1][0] == "M12") {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
} else if (array[0] == "U15" && array[1] == "U14") {
|
|
|
|
return d[0] == "U13" ? true : false;
|
|
} else if (array[0] == "S17" && array[1] == "U14") {
|
|
|
|
return d[0] == "U14" ? true : false;
|
|
}
|
|
|
|
let returndata = false;
|
|
d.forEach((x) => {
|
|
console.log(array, x, d);
|
|
if (array[0] < x && x < array[1]) {
|
|
returndata = true;
|
|
} else if (array[0] < x && x == array[1]) {
|
|
returndata = true;
|
|
} else if (array[1] == x && x < array[0]) {
|
|
returndata = true;
|
|
} else if (array[1] < x && x < array[0]) {
|
|
returndata = true;
|
|
}
|
|
});
|
|
|
|
return returndata;
|
|
});
|
|
return allThroughStation;
|
|
}
|
|
} catch (e) {
|
|
// エラーが発生した場合は空の配列を返す
|
|
}
|
|
};
|