Skip to content

Commit 110e9f5

Browse files
committed
ThoughWorksHomeWork
1 parent 4690917 commit 110e9f5

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

‎ThoughWorks/2018_SPRING_DEV .pdf‎

94.6 KB
Binary file not shown.

‎ThoughWorks/plane.html‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<script>
9+
/*
10+
1. 题目要求输入两个值,一个是文本内容,一个是消息序列,即两个参数
11+
2. 判断无人机的ID和和坐标位置
12+
3. 无人机飞行时传回来的坐标是否有故障
13+
4. 消息测试
14+
比如: plane 1 1 1 plane 1 1 1 1 2 3
15+
*/
16+
function get(infomation,signalIndex){
17+
let planeInfomation=infomation;
18+
let planeName=planeInfomation.split(' ')[0];
19+
let regName=/^[A-Za-z0-9]+$/gi;
20+
let location=infomation.split(`${planeName}`);//此时是带有空格的数组里面包着字符串,为了后面计算坐标方便需要转换为数字数组
21+
//console.log(infomation);
22+
let locations=location.map(function(ele,index,array){
23+
return ele.trim().split(' ').join('');
24+
}).slice(1);
25+
location=location.map(function(ele,index,array){
26+
return ele.trim().split(' ');
27+
}).slice(1)
28+
//判断坐标是不是数字
29+
let isNumber=locations.every(function(ele){
30+
return (ele-0);
31+
});
32+
if(regName.test(planeName)&&isNumber===true&&location[0].length==3){
33+
//如果消息不存在
34+
if(location.length<(signalIndex+1)){
35+
alert(`Cannot found : ${signalIndex}`);
36+
return `Cannot found : ${signalIndex}`
37+
}else{//消息存在,应该对坐标值进行计算
38+
//保存初始位置
39+
let a=location[0][0];
40+
let b=location[0][1];
41+
let c=location[0][2];
42+
let arr=[a,b,c];
43+
let locationArr=[];//用于保存所有的坐标值
44+
locationArr.push(arr);
45+
for(let i=0;i<location.length;i++){
46+
//第二行数据
47+
if(i==1){
48+
if(((location[0][0]==location[1][0])===true)&&((location[0][1]==location[1][1])===true)&&((location[0][2]==location[1][2])===true)&&(location[1].length==6)){
49+
a=location[1][0]-0+(location[1][3]-0);
50+
b=location[1][1]-0 + (location[1][4]-0);
51+
c=location[1][2]-0 + (location[1][5]-0);
52+
arr=[a,b,c];
53+
locationArr.push(arr);
54+
}else{
55+
//坐标有误
56+
let r = ["na", "na", "na"];
57+
locationArr.push(r);
58+
}
59+
}
60+
if(i>1){
61+
//判断当前的坐标的起始位置是不是上次坐标的位置
62+
if(((location[i][0]==locationArr[i-1][0])==true)&&((location[i][1]==locationArr[i-1][1])==true)&&((location[i][2]==locationArr[i-1][2])==true)&&(location[i].length==6)){
63+
//把坐标的起始位置加上偏移量,计算出现在坐标的位置作为下次坐标的起始位置,保存到数组
64+
a=location[i][0]-0+(location[i][3]-0);
65+
b=location[i][1]-0 + (location[i][4]-0);
66+
c=location[i][2]-0 + (location[i][5]-0);
67+
arr=[a,b,c];
68+
locationArr.push(arr);
69+
}else{
70+
//坐标有误
71+
let r = ["na", "na", "na"];
72+
locationArr.push(r);
73+
}
74+
}
75+
}
76+
if(locationArr[signalIndex][0]=='na'){
77+
alert(` Error:${signalIndex}`);
78+
return ` Error:${signalIndex}`;
79+
}else{
80+
alert(`${planeName}${signalIndex} ${locationArr[signalIndex]}`);
81+
return `${planeName}${signalIndex} ${locationArr[signalIndex]}`;
82+
}
83+
}
84+
}else{
85+
alert("无人机处于故障");
86+
}
87+
}
88+
get('plane 1 1 1 plane 1 1 1 1 2 3',3);
89+
</script>
90+
</body>
91+
</html>

0 commit comments

Comments
 (0)