学习是最好的投资!
break 是可以去掉的…
let arr = [1, 2, 3, 4, 5, 6, 7, 8] let result = [] for (let i = 0; i < arr.length - 1; i++) { // 每次循环重置 result result = [] for (let j = 0; j < arr.length; j++) { result.push(arr[j]) if (j >= i) break } console.log(result) }
循环的这个juli[b] 每次都不能正确的加入到数组里面
条件符合我就用break打断
如acc获取的下标到5,就将前1234求和 依次类推
for (var a = 0; a < cresult.length; a++) { for (var i = 1, j = 0; i < arr.length; i++, j++) { result[j] = [countDisPoToLine(cresult[a]["2"], cresult[a]["1"], arr[j]["2"], arr[j]["1"], arr[i]["2"], arr[i]["1"]), arr[i]["1"], arr[i]["2"], arr[j]["1"], arr[j]["2"], arr[j]["0"], lineDis(arr[i]["1"], arr[i]["2"], arr[j]["1"], arr[j]["2"])]; arrjoin[j] = result[j][0]; //循环数组中第一组关于距离的值 juli[j] = result[j][6]; } //console.log(juli); mindis = Math.min.apply(Math, arrjoin); // //console.log(arrmin.length, "点距线最短距离"); console.log(mindis, "点距线最短距离"); //result = []; for (var b = 0; b < result.length; b++) { ///sum = lineDis(result[b][1],result[b][2],result[b][3],result[b][4]); //计算两点之间的长度 acc = isHasElementTwo(arrjoin, mindis); //查找item 在array中的下标位置 sum.push(juli[b]); //console.log(juli[b]); //console.log(sumb(acc,juli)); if (b == acc) //满足最近点下标的条件,连续相加产生连续里程。 { minxy = getPointOnPolyline(cresult[a]["2"], cresult[a]["1"], result[b][4], result[b][2], result[b][3], result[b][1]); ctt = lineDis(result[b][3], result[b][4], minxy[1], minxy[0]); console.log(minxy, "垂足坐标"); console.log(ctt, "距离最近点的距离"); break }; } //abc.push(sum ); //console.log(eval(abc.join("+"))); console.log(sum); }
**1.0374510479565615 "点距线最短距离" (index):84[736260.8899769672, 1411419.6883407037] "垂足坐标" (index):10217.38691589480421 "距离最近点的距离" (index):104[13.999781212443958, 54.4198045292843, 70.38912223496114, 10.536416088967684, 685.858750934864, 255.56736787796788, 157.4782249233069, 62.58699880968758, 646.6167989543939, 313.57803581242166, 1067.5293031990727, 958.2300622502552, 417.420483917605, 64.57688332512566, 216.4881564657956, 316.1135609002259, 81.2835112492013, 56.39033259343886, 561.7188548465188, 142.39781082935613, 893.5690953081938, 92.02929710155902, 16.993059288952495, 14.314772824074824, 14.785963614054475, 20.720394204841156, 29.40872826215661, 22.45736237849337, 19.645029625828716, 28.46256518660203, 41.71105215644795, 18.333020182101933, 16.94088291682246, 32.23066924532746, 14.250265576472243, 204.50641699722792, 20.740160172962312, 24.035660943608878, 13.999781212443958, 54.4198045292843, 70.38912223496114, 10.536416088967684, 685.858750934864, 255.56736787796788, 157.4782249233069, 62.58699880968758, 646.6167989543939, 313.57803581242166, 1067.5293031990727, 958.2300622502552, 417.420483917605, 64.57688332512566, 216.4881564657956, 316.1135609002259, 81.2835112492013, 56.39033259343886, 561.7188548465188, 142.39781082935613, 893.5690953081938, 92.02929710155902, 16.993059288952495, 14.314772824074824, 14.785963614054475, 20.720394204841156, 29.40872826215661, 22.45736237849337, 19.645029625828716, 28.46256518660203, 41.71105215644795, 18.333020182101933, 16.94088291682246, 32.23066924532746, 14.250265576472243, 204.50641699722792, 20.740160172962312, 13.999781212443958, 54.4198045292843, 70.38912223496114, 10.536416088967684, 685.858750934864, 255.56736787796788, 157.4782249233069, 62.58699880968758, 646.6167989543939, 313.57803581242166, 1067.5293031990727, 958.2300622502552, 417.420483917605, 64.57688332512566, 216.4881564657956, 316.1135609002259, 81.2835112492013, 56.39033259343886, 561.7188548465188, 142.39781082935613, 893.5690953081938, 92.02929710155902, 16.993059288952495, 14.314772824074824, 14.785963614054475]**
break 是可以去掉的…
循环的这个juli[b] 每次都不能正确的加入到数组里面
条件符合我就用break打断
如acc获取的下标到5,就将前1234求和 依次类推
**1.0374510479565615 "点距线最短距离" (index):84
[736260.8899769672, 1411419.6883407037] "垂足坐标" (index):102
17.38691589480421 "距离最近点的距离" (index):104
[13.999781212443958, 54.4198045292843, 70.38912223496114, 10.536416088967684, 685.858750934864, 255.56736787796788, 157.4782249233069, 62.58699880968758, 646.6167989543939, 313.57803581242166, 1067.5293031990727, 958.2300622502552, 417.420483917605, 64.57688332512566, 216.4881564657956, 316.1135609002259, 81.2835112492013, 56.39033259343886, 561.7188548465188, 142.39781082935613, 893.5690953081938, 92.02929710155902, 16.993059288952495, 14.314772824074824, 14.785963614054475, 20.720394204841156, 29.40872826215661, 22.45736237849337, 19.645029625828716, 28.46256518660203, 41.71105215644795, 18.333020182101933, 16.94088291682246, 32.23066924532746, 14.250265576472243, 204.50641699722792, 20.740160172962312, 24.035660943608878, 13.999781212443958, 54.4198045292843, 70.38912223496114, 10.536416088967684, 685.858750934864, 255.56736787796788, 157.4782249233069, 62.58699880968758, 646.6167989543939, 313.57803581242166, 1067.5293031990727, 958.2300622502552, 417.420483917605, 64.57688332512566, 216.4881564657956, 316.1135609002259, 81.2835112492013, 56.39033259343886, 561.7188548465188, 142.39781082935613, 893.5690953081938, 92.02929710155902, 16.993059288952495, 14.314772824074824, 14.785963614054475, 20.720394204841156, 29.40872826215661, 22.45736237849337, 19.645029625828716, 28.46256518660203, 41.71105215644795, 18.333020182101933, 16.94088291682246, 32.23066924532746, 14.250265576472243, 204.50641699722792, 20.740160172962312, 13.999781212443958, 54.4198045292843, 70.38912223496114, 10.536416088967684, 685.858750934864, 255.56736787796788, 157.4782249233069, 62.58699880968758, 646.6167989543939, 313.57803581242166, 1067.5293031990727, 958.2300622502552, 417.420483917605, 64.57688332512566, 216.4881564657956, 316.1135609002259, 81.2835112492013, 56.39033259343886, 561.7188548465188, 142.39781082935613, 893.5690953081938, 92.02929710155902, 16.993059288952495, 14.314772824074824, 14.785963614054475]**