Skip to content

Instantly share code, notes, and snippets.

@onbjerg
Last active September 9, 2015 15:47
Show Gist options
  • Save onbjerg/3d0e0c0c917d2975c55f to your computer and use it in GitHub Desktop.
Save onbjerg/3d0e0c0c917d2975c55f to your computer and use it in GitHub Desktop.
(defn factorial [n]
(if (= n 1)
n
(* n (factorial (dec n))))
(print (factorial 7))
function f(n) {
var j = 1;
for(var i = n; i > 0; i--) {
j *= i
}
return j
}
console.log(f(7)) // 5040
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