We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function fun(...dimentions){ const [layer,...d] = dimentions; return d.length ? Array(layer).fill(0).map(_ => fun(...d)) : Array(layer) }
The text was updated successfully, but these errors were encountered:
const [layer,...d] = dimentions; 属于结构操作,从代码中可以看出来如果函数参数个数大于 1 个时就会进行递归操作,每次调用都会生成一个数组,长度为函数的第一个参数 layer,并且每次递归都会生成一个维度的数组,维度的大小有函数参数的个数觉得,每一维度中数组的长度由当前函数调用的第一个参数决定,当函数参数只有一个时终止递归调用并且生成一个长度为 layer 的数组;
const [layer,...d] = dimentions;
layer
fun(2) // = Array(2) fun(3) // = Array(3) fun(4) // = Array(4) fun(2,3) // Array( Array(3),Array(3) ) fun(2,3,4) // Array( Array( Array(4),Array(4),Array(4) ) , Array( Array(4),Array(4),Array(4) ) )
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: