-
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
Mock Question 3b, c [2122 Sem 1] #590
Comments
hi! i think my method is similar to yours for 3a, but instead of applying the function to list[x], i applied it to arr[x]. for 3b, i added a whereas for my function in 3c, i defined it as i am not sure if it is right though, i feel like i might be hardcoding it |
Hi, I think you actually already have what you need to solve 3(b), but just need to fit into the requirements slightly. This is from my rough understanding. The difference between (a) and (b) is the function that is used as the argument. For (c), similar to what you already did, I just generated indexes and used some methods to get the correct output. To answer your question, the length of the stream should be determined by the array argument that you push into the function. Not 100% sure this is correct, but this solution works through JShell. Probably better to update the Function to UnaryOperator as well. |
3a) Arrays.stream(arr).map(f).toArray() |
Source
2122 Semester 1 Finals
Description
Hi guys, anyone has any idea for solving 3b and c? I can't seem to think of the solution.
For 3a, I did this (I guess
rangeClosed()
will work too)return IntStream .iterate(0, x -> x + 1) .limit(arr.length) .map(x -> fn.apply(list[x])) .toArray(); }
Using my 3a approach, how do we know the length of the stream to generate before mapping for 3b? Or is there a better approach?
Would be grateful for any discussion. Thank you in advance :)
The text was updated successfully, but these errors were encountered: