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
假设一个数组arr = [2,5,7,8] arr.map((item)=>{ return item * 2; }) 如上代码会产生一个元素都为2倍的新数组。用reduce怎么实现呢,看代码:
arr.map((item)=>{ return item * 2; })
arr.reduce((prev, next)=>{ return prev.push(next * 2); }, [])
重点在于reduce的第二个参数,初始化为一个空数组。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
假设一个数组arr = [2,5,7,8]
arr.map((item)=>{ return item * 2; })
如上代码会产生一个元素都为2倍的新数组。用reduce怎么实现呢,看代码:
重点在于reduce的第二个参数,初始化为一个空数组。
The text was updated successfully, but these errors were encountered: