Last active
September 9, 2015 15:47
-
-
Save onbjerg/3d0e0c0c917d2975c55f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn factorial [n] | |
(if (= n 1) | |
n | |
(* n (factorial (dec n)))) | |
(print (factorial 7)) |
This file contains hidden or 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
function f(n) { | |
var j = 1; | |
for(var i = n; i > 0; i--) { | |
j *= i | |
} | |
return j | |
} | |
console.log(f(7)) // 5040 |
This file contains hidden or 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
def factorial(n) | |
return n if n == 1 | |
n * factorial(n - 1) | |
end | |
puts factorial(7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment