【问题标题】:How to creat a function to return an array with 21 waypoints separated如何创建一个函数来返回一个分隔 21 个航点的数组
【发布时间】:2023-03-15 19:32:01
【问题描述】:

我想创建一个包含 21 个航点的 3 个位置的数组..~ 为此,我需要这样的功能: 我的默认数组:waypt2 = [Array(22), Array(22), Array(17)]

function work_waypoints(waypt2){
    waypts.push({
      location: waypt2[i][g].latlgn,
      stopover: true // obrigatório paragem
    });
    return waypts;
  }

【问题讨论】:

  • 哪些航路点应该去哪个位置?
  • 你的输入输出是什么?

标签: javascript directions


【解决方案1】:

我不确定你想在这里做什么。据我了解,也许您可​​以对数组内容尝试这样的操作:

Array.from(
  { length: 21 },
  (_, index) => ({
    stopover: true,
    location: object[index] // ...
  })
)

【讨论】:

    【解决方案2】:

    以下代码生成以随机整数为位置的航路点,

    function generateWaypoints(){
      console.log(Array.from({length: 3}, () => Math.floor(Math.random() * 150)));
    }
    
    Function.prototype.sequence = function(from, to) {
        for (var i = from; i <= to; i++) this.call(null, i);
    };
    
    generateWaypoints.sequence(0, 21);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-26
      • 2022-01-15
      • 2016-10-12
      • 1970-01-01
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多