Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:56:41+00:00 2026-06-17T18:56:41+00:00

chapter6 My english is poor can’t describe the problem in detail so I paste

  • 0

chapter6

My english is poor can’t describe the problem in detail so I paste my practice code:http://jsbin.com/exusox/3/edit

Endless loop when you click the butten.

I’ve tested my code,I found the endless loop in this code:

function extractFootnotes(paragraphs){
    var footnotes=[],currentNum=0;
    function dealWithFootnote(fragment){
      if(fragment.type=="footnote"){
        currentNum++;
        fragment.number=currentNum;
        footnotes.push(fragment);
        return {type:"reference",number:currentNum};
      }
      else{
        return fragment;
      }
    }
    //run here ,endless loop happened.I've tested forEach,the i++ can't work.
    forEach(paragraphs,function(paragraph){
      paragraph.content=map(dealWithFootnote,paragraph.content);
    });

    return footnotes;
  }


  function forEach(array,action){
    for(i=0;i<array.length;i++)
      action(array[i]);
  }

  function map(func,array){
    var result=[];
    forEach(array,function(element){
      result.push(func(element));
    });
    return result;
  }

Why this happen and How can I reduce my code?Thanks.

My Practice Code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:56:42+00:00Added an answer on June 17, 2026 at 6:56 pm

    The variable “i” in your “forEach” function is a global variable. You should declare it with var:

    function forEach(array, action) {
      var i;
      // ... etc
    }
    

    Thus when one call to “forEach” involves an action that will itself call “forEach”, the same variable “i” will be reset.

    It’s a good idea to put this at the top of your code:

    "use strict";
    

    That tells the interpreter to apply some newer rules to the code, and it’d show you an error like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://ruby.railstutorial.org/chapters/static-pages#code:pages_controller_spec_title My code is as follows. When uncommented the test wont run. Below is
As shown in here: http://www.learningjquery.com/2007/03/accordion-madness . But I need help to edit it so
I'm thinking of translating a book from English to my native language. I can
I am reading chapter 2 of Advanced Linux Programming: http://www.advancedlinuxprogramming.com/alp-folder/alp-ch02-writing-good-gnu-linux-software.pdf In the section 2.1.3
SICP Chapter 3.5.3 http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5.3 In section Streams as signals , SICP gives an audio-visual
I am reading Chapter 17 of C Primer Plus, and here is the code
How can I check if some fields in my word have errors? I have
Chapter about TDD from Martin's Clean Code caught my imagination. However. These days I
On Chapter 7 from Michael Hartl's tutorial there is a User model < code
(sorry for any bad English) Let's suppose I have models A, B, C. Each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.