Skip to content

Update GettingStartedWithFPSection.scala #43

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

Merged
merged 1 commit into from
Jun 24, 2019

Conversation

slashdev1
Copy link
Contributor

I think function isSorted has a mistake because isSorted(Array(1, 3, 5, 7), (x: Int, y: Int) => x > y) should be return false:
in the first step condition 1 > 3 is false

I mean function isSorted has a mistake because isSorted(Array(1, 3, 5, 7), (x: Int, y: Int) => x > y) should be return false:
first step 1 > 3 is false
@FRosner
Copy link
Member

FRosner commented Jun 19, 2019

Hi! Thanks for the contribution. It is confusing to me indeed why the higher order function, which is the sorted condition, is negated in the current implementation. If you are modifying the logic however you either need to invert all the conditions in the exercises or change the expected values in https://github.com/scala-exercises/exercises-fpinscala/blob/master/src/test/scala/fpinscalalib/GettingStartedWithFPSpec.scala#L24

@slashdev1
Copy link
Contributor Author

slashdev1 commented Jun 19, 2019

Hi. Thanks for the answer. How do you mean it is good idea if I'll change conditions signs in method isSortedAssert below isSorted: > to < and < to >

@FRosner
Copy link
Member

FRosner commented Jun 21, 2019

I think that makes sense but maybe I'm not getting what the method is supposed to do. Can you find out the original author and ping them here?

@slashdev1
Copy link
Contributor Author

Hello @jdesiloniz Can you read my previous post and answer it.

@jdesiloniz
Copy link

@slashdev1 @FRosner Hello, and thanks for this PR! I think I added that negation by mistake while writing that exercise. I'd move forward with your PR if no one has any objections! 👍

@jdesiloniz jdesiloniz merged commit f2bdb32 into scala-exercises:master Jun 24, 2019
@FRosner
Copy link
Member

FRosner commented Jun 25, 2019

We should fix the test I guess? We can't just change the code without changing the test, or?

@jdesiloniz
Copy link

jdesiloniz commented Jun 25, 2019

@FRosner Yeah, fixed this in the following PR: #46. Unfortunately the issues that we had with Travis and the JDK masked the test issue.

@vgrigoriu
Copy link

I think the original implementation is correct. If as(n) and as(n + 1) are not ordered, then the whole sequence is not ordered. I think isOrdered(Array(1, 2, 3), (x: Int, y: Int) => x <= y) should be true and isOrdered(Array(1, 2, 3), (x: Int, y: Int) => x > y) should be false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants