Last active
January 31, 2016 06:12
-
-
Save iboss-ptk/c4a96664e165f36ddf8a to your computer and use it in GitHub Desktop.
This file contains 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
val accumulatingList = numbers | |
.foldLeft(List[Int]())((acc, curr) => | |
if(!acc.isEmpty) acc :+ (acc.last + curr) else acc :+ curr) | |
// => List(1, 3, 6, 10, 15) | |
def contains(numbers: List[Int], target: Int) = | |
numbers.foldLeft(false)((acc, curr) => if(curr == target) true else acc || false) | |
contains(numbers, 4) // => true | |
contains(numbers, 20) // => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment