Skip to content

Commit

Permalink
国境を越える場合に水泳と表示するようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
hutinoatari committed Oct 11, 2024
1 parent c22fd87 commit 7d1110b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ <h1>最安経路検索</h1>
<form name="locationData">
<div>
<label>
出発地点<input>
出発地点: <input>
</label>
</div>
<div id="relayPoints"></div>
<div>
<label>
到着地点<input>
到着地点: <input>
</label>
</div>
</form>
Expand Down
20 changes: 16 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
const isJapanPoint = name => {
const regJapaneseplace = /[ぁ-ん亜-熙]/;
return regJapaneseplace.test(name);
}

const searchTransfer = () => {
const points = document.forms.locationData.elements;
const pointArray = Array.from(points).map((point) => point.value.trim());
if(pointArray[0] === "" || pointArray[pointArray.length-1] === ""){
const pointArray = Array.from(points).map((point) => point.value.trim()).filter(point => point !== "");
if(pointArray.length < 2){
alert("不正な入力です。")
return;
}
const text = pointArray.filter(point => point !== "") .join("\n| (徒歩)\n");
//const text = pointArray.filter(point => point !== "") .join("\n| (徒歩)\n");
let text = "";
for(let i=0; i<pointArray.length; i+=1){
text += pointArray[i];
if(i === pointArray.length-1) break;
const transportation = isJapanPoint(pointArray[i]) === isJapanPoint(pointArray[i+1]) ? "徒歩" : "水泳";
text += `\n|(${transportation})\n`;
}
const output = document.querySelector("output");
const button = document.querySelectorAll("button")[1];
output.innerText = "検索中...";
Expand All @@ -21,7 +33,7 @@ const searchTransfer = () => {
const addRelayPoint = () => {
const div = document.createElement("div");
const label = document.createElement("label");
const labelText = document.createTextNode("中継地点");
const labelText = document.createTextNode("中継地点: ");
const input = document.createElement("input");
label.appendChild(labelText);
label.appendChild(input);
Expand Down

0 comments on commit 7d1110b

Please sign in to comment.