code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

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:11:16+05:18 · Edit