click on the top

“Front end talent” can subscribe oh!

Original title: “Three Ways to Factorialize a Number in JavaScript”

Sonya Moisset

The original link: https://medium.freecodecamp.com/how-to-factorialize-a-number-in-javascript-9263c89a4b38

2. The English version of the dictionary is translated by the English version of the dictionary

Front-end technology changes with each new day, a lot of new technical articles are in English, which requires us to have a good English ability, from today on small make up and we learn English while learning the front end, due to limited ability, welcome everyone correct, together to improve English.

This article is based on Free Code Camp Basic Algorithm Scripting “Factorialize a Number”.

Translation:

This article is based on the Free Code Camp basic algorithm script “Digital factorials”.

Note: Free Code Camp is a Free online learning website. Web site address: https://www.freecodecamp.com

Key words:

algorithm

An algorithm, esp in a computer program

In mathematics, the factorial of a non-negative integer n can be a tricky algorithm. In this article, I’m going to explain three approaches, first with the recursive function, second using a while loop and third using a for loop.

Translation:

In mathematics, factorial of a non-negative integer n can be a tricky algorithm. In this article, I’ll do it three ways, first with recursive functions, second with a while loop, and third with a for loop.

Key words:

factorial

It is a factor of two

N. The factorial product

non-negative

non-negative

tricky

Difficult to deal with; Difficult to deal with; Tricky; Crafty; scheming. The treacherous; Sly.

approach

vt.& Come near, come near, come near

Vt. Close to; Get to grips with; Make closer; Try to bribe (or influence, smooth)

N. method; Way; Close to the

Vi. Near

recursive function

Recursive function

We have already seen a recursion approach on a String in the previous article, How to Reverse a String in JavaScript in 3 Different Ways ?This time we will apply the same concept on a number.

Translation:

We’ve seen recursion in string manipulation in the last article. How do you reverse strings in JavaScript in three different ways?This time we’ll apply the same concepts to Numbers.

Key words:

concept

Concept; Point of view; Thought, conception, idea; The overall impression

Algorithm Challenge

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.

So, flexibly?B: Well, general rules are often terrible.

For example: 5! So it’s 1 times 2 times 3 times 4 times 5, which is 120

Translation:

Challenge algorithm

Returns the factorial of a specified integer.

If integers are represented by the letter N, the factorial is the product of all positive integers less than or equal to N.

Factorial is usually written in shorthand notation N! Said.

For example: 5! So it’s 1 times 2 times 3 times 4 times 5, which is 120

The function factorialize (num) {

return num;

}

factorialize(5);

Key words:

represented

V. representative; Reflect; To represent (a past tense and past participle); As a… The representative of the

positive

adj.

Positive; Be sure of STH. Positive; Positive

n.

Positive; Positive; [Language] a primal adjective; Positive quantity

shorthand notation

Simplify the symbol

Provided the test cases

Factorialize (0) should return 1factorialize(5) should return 120factorialize(10) should return 3628800factorialize(20) should return 2432902008176640000

Translation:

Provide test cases:

Factorialize (0) should return 1factorialize(5) should return 120factorialize(10) should return 3628800factorialize(20) should return 2432902008176640000

Key words:

provided

Conj. If; If; In the… Under the condition of

A. provide B. provide C. provide D. provide

What is factorializing a number all about?

When you factorialize a number, you are multiplying that number by each consecutive number minus one.

If your number is 5, you would have:

5! = 5 * 4 * 3 * 2 * 1

The pattern would be:

0! = 1

1! = 1

2! = 2 * 1

3! = 3 * 2 * 1

4! = 4 * 3 * 2 * 1

5! So it’s 5 times 4 times 3 times 2 times 1

Translation:

What exactly is a digital factorial?

When you take the factorial of a number, decrease the number by 1 each time and multiply.

If the number is 5, you should look like this:

5! So it’s 5 times 4 times 3 times 2 times 1

This pattern will:

0! = 1

1! = 1

2! = 2 * 1

3! = 3 * 2 * 1

4! = 4 * 3 * 2 * 1

5! So it’s 5 times 4 times 3 times 2 times 1

Key words:

consecutive

Continuous, continuous, or continuous; Indicating the result

multiplying

Six (multiply) four times from six. Multiply; multiply. Add to; add to Breed

1. Factorialize a Number With Recursion

The function factorialize (num) {

if (num < 0)

return -1;

Else if (num == 0)

return 1;

The else {

return (num * factorialize(num – 1));

}

}

factorialize(5);

2 Factorialize a Number with a WHILE loop

The function factorialize (num) {

var result = num;

If (num === 0 || num === 1)

return 1;

while (num > 1) {

num–;

result *= num;

}

return result;

}

factorialize(5);

3 Factorialize a Number with a FOR loop

The function factorialize (num) {

If (num === 0 || num === 1)

return 1;

for (var i = num – 1; i > = 1; I -) {

num *= i;

}

return num;

}

factorialize(5);

About today’s article sharing here, I hope you have a harvest, about the original English please click on the original reading view (need over the wall to see, you know)

The public,

The front-end talent

Long press to identify the left two-dimensional code to follow me click below “read the original” to view the English text down down down

### Read More:

- Solved! The new version of statsmodels has the problem of importerror: cannot import name ‘factorial’
- 26 English letters in upper and lower case and 0-9 to generate 8-bit random password
- Change the path in the user directory in Chinese Ubuntu to English
- Several ways to view spark task log
- Python error: resource u’tokenizers / Punkt/ english.pickle ‘ not found.
- Chinese garbled fonts in win10 English system
- Four ways to get Django parameters in request
- Python parallel processing makes full use of CPU to realize acceleration
- Java uses lock to realize multithread sequential alternate execution mode 2
- Three ways to get form data in struct2
- How to realize automatic assembly in springboot
- How to install scikit learn and other scientific computing libraries in Ubuntu 16.04
- CSS: several ways to center the box vertically and horizontally
- Using xrdp to realize windows remote desktop Ubuntu Linux
- Count the frequency of words in English documents
- Solution to Vue cli · failed to download repo vuejs templates/webpack: connect etimeout followed by an IP digital error message
- Installing sklearn (scikit learn) module related to Python machine learning in Windows
- Several ways to center elements horizontally and vertically
- Selenium: 8 Ways to Locate Elements
- What can I learn from Kenshi