The Wayback Machine - https://web.archive.org/web/20201018034630/https://github.com/InterviewMap/CS-Interview-Knowledge-Map/issues/153
Skip to content
New issue

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

flatMap 的示例有误 #153

Open
zhuweiyou opened this issue Sep 28, 2018 · 0 comments
Open

flatMap 的示例有误 #153

zhuweiyou opened this issue Sep 28, 2018 · 0 comments

Comments

@zhuweiyou
Copy link

@zhuweiyou zhuweiyou commented Sep 28, 2018

https://github.com/InterviewMap/CS-Interview-Knowledge-Map/blob/master/JS/JS-en.md#mapflatmap-and-reduce

[1, [2], 3].flatMap((v) => v + 1)
// -> [2, 3, 4]

上面这个,运行结果是不正确的,而且没有表达 flatMap 的作用
应该是类似这样

const arr = [1, 2, 3, 4]
arr.map(x => [x * 2])
// [[2], [4], [6], [8]]

arr.flatMap(x => [x * 2])
// [2, 4, 6, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.