-
Notifications
You must be signed in to change notification settings - Fork 0
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
pyp 20/21 sem 1 #588
Comments
hmm can u try this. [.reduce(0, (a,b) -> a + b.length(), (a,b) -> a + b);] not sure if this is what the question is asking for. Or, you can do this .reduce("", (a,b) -> a + b).length(); i think both works. |
I think this question is testing Stream's 2 arguments reduce in (d) and 3 arguments reduce in (e). For (e), since we have to reduce directly from a stream of String and return int, the only reduce we can use is the 3 arguments reduce. This is due to the difference in the seed/identity type, where for the reduce with 2 arguments the seed/identity must be the same type as the stream but not for the reduce with 3 arguments. |
Use either reduce(0, (x,y) -> x + y.length(), (x,y) -> x + y); or .reduce("", (x,y) -> x + y).length() |
Personally i defined it as int count(List words) { |
I used this: words.stream().reduce(0, (x,y) -> x + y.length(), (x,y) -> x+ y) |
thank you guysss :> all the best for finals !! |
int count(List words) { |
int count(List words) { |
cs2030(s) ay2020/21 qn6 streams:
Hiii im not very sure on how to do qn 6 (e).... please help thank you!
The text was updated successfully, but these errors were encountered: