Skip to content

Instantly share code, notes, and snippets.

@RyanSusana
Created May 29, 2020 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanSusana/61b0298707561821e0a78d47f2dcee2e to your computer and use it in GitHub Desktop.
Save RyanSusana/61b0298707561821e0a78d47f2dcee2e to your computer and use it in GitHub Desktop.
// Returns the input
def identity(x: Int) = x
// Calculates cube of a number
def cube(x: Int) = x * x * x
// Calculates factorial of a number
def factorial(x: Int): Int =
if (x <= 1) 1 else x * factorial(x - 1)
//Sum function, adds up all ints between a and b
def sum(a: Int, b: Int): Int =
if (a > b) 0 else a + sum(a + 1, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment