Created
March 23, 2016 06:50
-
-
Save sujeet100/06ac25aee6c06355cd52 to your computer and use it in GitHub Desktop.
Scala syntax
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
// Sum of an array | |
def f(arr:List[Int]):Int = arr.reduceLeft(_+_) | |
//sum of odd numbers in an array | |
//reduceLeft does not take inital value | |
def f(arr:List[Int]):Int = arr.foldLeft(0)((a, b)=> if(b%2==1) a+b else a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment