[英]Why am I getting this 'cannot read property 'length' of undefined'? (JavaScript)
Granted it's the end of a long week and my brain's fried, but I'm at my wit's end with this. 当然,这已经是一个漫长的一周的结束了,我的大脑被炸了,但是我为此感到无所适从。 Why on earth am I getting this error with respect to
options.length
when it's a function parameter and it was passed in an array argument ( assortment
)? 为什么当我将它作为函数参数并以数组参数(
assortment
)传递时,为什么会遇到关于options.length
错误?
(I'm trying to come up with a recursive solution to provide permutations (repetitions allowed) of an assortment of characters in an array) (我正在尝试提出一种递归解决方案,以提供数组中各种字符的排列(允许重复))
var n = 10;
var assortment = ['a','b','c','d','e'];
console.log(permutations(n, assortment));
function permutations (num, options) {
var solutions = [];
var singleSet = [];
if (singleSet.length === num) {
solutions.push(singleSet);
return;
} else {
for (var i=0; i < options.length; i++) {
singleSet = singleSet.concat(permutations(options[i]));
}
}
return solutions;
}
您仅在此处传递一个参数:
singleSet = singleSet.concat(permutations(options[i]));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.