52 lines
1.5 KiB
JavaScript
52 lines
1.5 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) => {
|
|
if (
|
|
(array[0] == "M12" && array[1] == "Y09") ||
|
|
(array[0] == "Y09" && array[1] == "M12")
|
|
)
|
|
return d[0] == "M12" ? true : false;
|
|
|
|
let returndata = false;
|
|
d.forEach((x) => {
|
|
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) {
|
|
console.log(e);
|
|
}
|
|
};
|