Skip to content

Instantly share code, notes, and snippets.

@sujeet100
Created March 23, 2016 06:50
Show Gist options
  • Save sujeet100/06ac25aee6c06355cd52 to your computer and use it in GitHub Desktop.
Save sujeet100/06ac25aee6c06355cd52 to your computer and use it in GitHub Desktop.
Scala syntax
// 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