Created
May 29, 2020 12:21
-
-
Save RyanSusana/61b0298707561821e0a78d47f2dcee2e 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
// 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