← Back to challenges

Double Factorial

JavaScriptHardrecursionnumbers

Instructions

Create a function that takes a number num and returns its double factorial.

Examples

doubleFactorial(0) ➞ 1

doubleFactorial(2) ➞ 2

doubleFactorial(9) ➞ 945
// 9*7*5*3*1 = 945

doubleFactorial(14) ➞ 645120

Notes

  • Assume all input values are greater than or equal to -1.
  • Try to solve it with recursion.
  • Double factorial is not the same as factorial * 2.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Factorize a Number