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
可以通过传入一个深度参数来限制 flat 方法的递归深度。实现如下:
function flat(arr, depth = 1) { let res = []; for (let i = 0; i < arr.length; i++) { if (Array.isArray(arr[i]) && depth > 0) { res = res.concat(flat(arr[i], depth - 1)); } else { res.push(arr[i]); } } return res; }
这里在原有的 flat 方法基础上增加了一个 depth 参数,每递归一层,深度就减一,当深度为 0 时就不再递归。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
可以通过传入一个深度参数来限制 flat 方法的递归深度。实现如下:
这里在原有的 flat 方法基础上增加了一个 depth 参数,每递归一层,深度就减一,当深度为 0 时就不再递归。
The text was updated successfully, but these errors were encountered: