본문 바로가기

Algorithms

freeCodeCamp - 3. Factorialize a Number [Basic Algorithm Scripting]

Factorialize a Number

 

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/factorialize-a-number

 

www.freecodecamp.org

 

function factorialize(num) {
  let sum = 1
  if(num > 0) {
    for(let i=1; i<num+1; i++){
      sum = sum*i
    }
  }
  return sum;
}

factorialize(5);