code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

049 Factorialize A Number

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */


/* 
Return the factorial of the provided integer.

If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.

Factorials are often represented with the shorthand notation n!

For example: 5! = 1 * 2 * 3 * 4 * 5 = 120
*/

function factorializeANumber(value) {
  if(value === 1){
    return 1
  }
  return value * factorializeANumber(value-1)
}

test('factorialize A Number', () => {
  expect(factorializeANumber(5)).toEqual(120)
});

Created 2019-12-14T23:23:16+05:30 · Edit