Created
July 17, 2013 14:30
-
-
Save willf/6021087 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def countMonotonicityBreaks(items: Seq[Int]): Int = | |
items.sliding(2). // two items at a time | |
filter(p => p.size == 2 && p(0) != p(1)). // remove any equalities | |
map{p => p(1).compare(p(0))}. // get -1 and 1 values; must have 2 values | |
sliding(2). // take *these* two at a time | |
count(p => p.size == 2 && p(0) != p(1)) // count when the differ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: https://gist.github.com/ryanlecompte/6017746