Skip to content

Instantly share code, notes, and snippets.

@okovalov
Created June 28, 2019 15:34
Show Gist options
  • Save okovalov/63a4e28d4904c08d9560d30103d9feee to your computer and use it in GitHub Desktop.
Save okovalov/63a4e28d4904c08d9560d30103d9feee to your computer and use it in GitHub Desktop.
const factorial = n => n < 0 ? 'n must be > 0' : n < 2 ? 1 : n * factorial(n - 1)
for (let i = -2; i <= 10 ; i++ ) {
console.time(`Time for ${i}`);
console.log(`factorial(${i}) = ${factorial(i)}`)
console.timeEnd(`Time for ${i}`)
}
console.log('-----')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment