雄辩的Javascript第7章-gamblerPath函数

雄辩的Javascript第7章-gamblerPath函数,javascript,function,Javascript,Function,在函数randomInteger中的gamblerPath函数中,执行名称所述的操作,选择一个随机整数 function gamblerPath(from, to) { function randomInteger(below) { return Math.floor(Math.random() * below); } function randomDirection(from) { var options = roadsFrom(from); return

在函数randomInteger中的gamblerPath函数中,执行名称所述的操作,选择一个随机整数

function gamblerPath(from, to) {
  function randomInteger(below) {
    return Math.floor(Math.random() * below);
  }
  function randomDirection(from) {
    var options = roadsFrom(from);
    return options[randomInteger(options.length)].to;
  }

  var path = [];
  while (true) {
    path.push(from);
    if (from == to)
      break;
    from = randomDirection(from);
  }
  return path;
}

show(gamblerPath("Hanaiapa", "Mt Feani"));

我的疑问与randomInteger下面的参数有关,它来自哪里?调用函数时没有传递它。有人吗?

当您调用
随机整数(options.length)
时,参数
options.length
是下面
的值


换句话说,你需要一个小于数组大小的随机数,因此你可以从数组中选择一个随机值。

作为初学者,我发现很难遵循函数可能具有的这种抽象路径。因此,谢谢你的解释。