## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
Patrick Hofer
@patrickhofer
hint
CamperBot
@camperbot

hint [3/8]

## Outline

This one starts easily since 0! = 1, so you can go ahead and simply return 1 there.

We can use that as an if in order to break the loop we're going to create using a recursive function. It will check if the number you gave the function is 0 (which would be the end of your factorial chain). Functions "end" when they return anything. In fact, all functions without an explicit return statement will return undefined.

This is also why instead of having "finished", a function is always said to "have returned". And now this...

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Krishna Sahu
@dvlprkrishna
bonfire factorialize
CamperBot
@camperbot

## :fire:Bonfire: Factorialize a Number :link:

function factorialize(num) {
return num;
}

factorialize(5);

Return the factorial of the provided integer.

more info:  bf details | bf links | hint

Krishna Sahu
@dvlprkrishna
hint
CamperBot
@camperbot

hint [1/8]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Krishna Sahu
@dvlprkrishna
hint
CamperBot
@camperbot

hint [2/8]

## # Problem Explanation:

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

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Krishna Sahu
@dvlprkrishna
hint
CamperBot
@camperbot

hint [3/8]

## Outline

This one starts easily since 0! = 1, so you can go ahead and simply return 1 there.

We can use that as an if in order to break the loop we're going to create using a recursive function. It will check if the number you gave the function is 0 (which would be the end of your factorial chain). Functions "end" when they return anything. In fact, all functions without an explicit return statement will return undefined.

This is also why instead of having "finished", a function is always said to "have returned". And now this...

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Krishna Sahu
@dvlprkrishna
hint
CamperBot
@camperbot

hint [4/8]

## Understanding recursion

Recursion refers to a function repeating (calling) itself. In this case we are basically returning the given number (i.e. 5), multiplied by the function itself but this time the value passed to the num parameter is num-1 (which initially translates to 4). The very function is going to run inside itself interesting, eh?

# Understanding the flow

The first returned value can be visualized better if you think about those parenthesis operations you did in secondary school where you do the math inside every parenthesis from inside out, bracket and square bracket until you get a final result (a total). This time it's the same thing, look at the program flow:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Krishna Sahu
@dvlprkrishna
hint
CamperBot
@camperbot

hint [5/8]

## # During the first execution of the function:

[num = 5]

Is 5 equal to 1 or 0? No ---> Oki doki, let's continue...

Returns:

(5 (second execution: 4 (third execution: 3 (_fourth execution: 2 _fifth execution: 1))))

What it returns can be viewed as (5*(4*(3*(2*1)))) or just 5 * 4 * 3 * 2 * 1, and the function will return the result of that operation: 120. Now, let's check what the rest of the executions do:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Landon
@landonbas
hint
CamperBot
@camperbot

hint [1/8]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Landon
@landonbas
hint
CamperBot
@camperbot

hint [2/8]

## # Problem Explanation:

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

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Landon
@landonbas
hint
CamperBot
@camperbot

hint [3/8]

## Outline

This one starts easily since 0! = 1, so you can go ahead and simply return 1 there.

We can use that as an if in order to break the loop we're going to create using a recursive function. It will check if the number you gave the function is 0 (which would be the end of your factorial chain). Functions "end" when they return anything. In fact, all functions without an explicit return statement will return undefined.

This is also why instead of having "finished", a function is always said to "have returned". And now this...

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Landon
@landonbas
hint
CamperBot
@camperbot

hint [4/8]

## Understanding recursion

Recursion refers to a function repeating (calling) itself. In this case we are basically returning the given number (i.e. 5), multiplied by the function itself but this time the value passed to the num parameter is num-1 (which initially translates to 4). The very function is going to run inside itself interesting, eh?

# Understanding the flow

The first returned value can be visualized better if you think about those parenthesis operations you did in secondary school where you do the math inside every parenthesis from inside out, bracket and square bracket until you get a final result (a total). This time it's the same thing, look at the program flow:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Landon
@landonbas
hint
CamperBot
@camperbot

hint [5/8]

## # During the first execution of the function:

[num = 5]

Is 5 equal to 1 or 0? No ---> Oki doki, let's continue...

Returns:

(5 (second execution: 4 (third execution: 3 (_fourth execution: 2 _fifth execution: 1))))

What it returns can be viewed as (5*(4*(3*(2*1)))) or just 5 * 4 * 3 * 2 * 1, and the function will return the result of that operation: 120. Now, let's check what the rest of the executions do:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Landon
@landonbas
hint
CamperBot
@camperbot

hint [6/8]

## # During the rest of the executions:

Second Execution:
num_ = 5-1 = 4 -> is _num 0 or 1? No<br>
--> return the multiplication between 4 and the next result when num is now 4-1.

Third Execution: num_ = 4 - 1 = 3 -> is _num 0 or 1? No<br>
--> return the multiplication between 3 and the next result when num is now 3-1.

Fourth Execution: num_ = 3-1 = 2 -> is _num 0 or 1? No<br>
--> return the multiplication between 2 and the next result when num is now 2-1.

Fifth Execution: num_ = 2-1 = 1 -> is _num 0 or 1? Yep<br>
--> return 1. And this is where the recursion stops because there are no more executions.

Got it? ;)

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Landon
@landonbas
hint
CamperBot
@camperbot

hint [7/8]

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Landon
@landonbas
hint
CamperBot
@camperbot

hint [8/8]

## Code Solution:

function factorialize(num) {
if (num === 0) { return 1; }
return num * factorialize(num-1);
}

factorialize(5);

# Credits:

If you found this page useful, you can give thanks by copying and pasting this on the main chat: Thanks @luishendrix92 @Rafase282 @hallaathrad for your help with Bonfire: Factorialize a Number

           ,,,         ,,,
;"   ^;     ;'   ",
;    s$$s ; , ss$$s  ,'
;s
P""Y$$Y""W$$$$-{ Happy Camping! }$$$$p"$$$"q $
  .$.  $$DcaU$$ "Y$$"*"$$$Y"
"$b.$\$"

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Shruti Hardat
@shrutihardat
hint Reverse a String
CamperBot
@camperbot
These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
dc
@dcsan
hint
CamperBot
@camperbot

hint [1/1]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

dc
@dcsan
hint
CamperBot
@camperbot
These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
dc
@dcsan
hint
CamperBot
@camperbot

hint [1/1]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

dc
@dcsan
bonfire numb
CamperBot
@camperbot

## :fire:Bonfire: Factorialize a Number :link:

function factorialize(num) {
return num;
}

factorialize(5);

Return the factorial of the provided integer.

more info:  bf details | bf links | hint

dc
@dcsan
bonfire chunky
CamperBot
@camperbot

function chunk(arr, size) {
// Break it up.
return arr;
}

chunk(['a', 'b', 'c', 'd'], 2);

Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a multidimensional array.

more info:  bf details | bf links | hint

dc
@dcsan
hint
CamperBot
@camperbot
These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
Christopher Eaton
@christopherpeaton
hint
CamperBot
@camperbot

hint [1/1]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

agm783
@agm783
hint
Einar Barzilay
@einarzb
hint
Bhavya Kamboj
@bhavyakamboj
hint
anybody got a hint yet.. this is sick