TAILIEUCHUNG - Học JavaScript qua ví dụ part 18

Đệ quy Nghĩa của đệ quy: đệ quy: Xem đệ quy. Định nghĩa này nói rằng tất cả! JavaScript hỗ trợ đệ quy. Vì vậy, nó là gì? Bạn đã bao giờ được tháo rời một con búp bê Nga? Mở con búp bê ra ngoài và có một bản sao nhỏ hơn búp bê bên trong nó, mất rằng một trong ra ngoài, và bạn thấy khác, và như vậy, cho đến khi bạn có thể giảm đến một con búp bê nhỏ ở cuối. | What Is a Function 161 Figure The closure remembers the values of local variables. Recursion Definition of recursion recursion See recursion. This definition says it all JavaScript supports recursion. So what is it Have you ever taken apart a Russian doll Open up the outside doll and there s another smaller duplicate doll inside it take that one out and you find another and so on until you get down to a tiny doll at the end. Then when you put them back you start with the last doll you opened and keep returning each doll until you get back to the first one you opened. A recursive function is a function that calls itself. It s a chain of function calls to the same function. The first time it calls itself is the first level of recursion the second time is the second level and so on. When a function calls itself execution starts at the beginning of the function and when the function ends the program backs up to where it was when it called the function and starts executing from that point. Most important there must be a way to stop the recursion or it will be infinite and probably cause the program to crash. An example often used to describe recursion can be demonstrated with a function to produce a Fibonacci sequence of numbers 0 1 1 2 3 5 8 13 21 34 55 and so on. Here is a little bit of history about how this formula was derived. In the beginning of the 13th century an Italian mathematician Leonardo Fibonacci was trying to solve the following problem presented at a mathematical competition in Pisa How many rabbits would be produced in a year if beginning with a single pair of rabbits every month each pair reproduces a new pair of rabbits which become productive when they are one month old and none of them die and so on Fibonacci came up From the Library of 162 Chapter 7 Functions with a formula named after himself to answer the rabbit question. The sequence starts with 0 and 1 and then produces the next number by adding the two previous .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.