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 6390493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:33:16+00:00 2026-05-25T03:33:16+00:00

i have an algorithm that generates permutations of a given word. I’m trying to

  • 0

i have an algorithm that generates permutations of a given word. I’m trying to use setInterval() to generate the next permutation but the function runs only once! I can’t figure out why. I don’t get any error messages.
Here is my code

var splitted;
var t;
 $(document).ready(function() {
$('#SubmitBtn').click(function() {
    //change Start to Stop and change button id
    $('#SubmitBtn').attr('id','StopBtn').attr('value','Stop');
    //and add click event to it
    $('#StopBtn').click(function() {
        clearInterval(t);
        $('#StopBtn').attr('value','Submit');
        $('StopBtn').attr('id','SubmitBtn');
    });
    if ($('#AnagramTxtArea').val().length>0)
            $('#AnagramTxtArea').text('');
    var inputTxt = $('#anagram').val();
    splitted = inputTxt.split("");
    splitted.sort(); //first sort the array in order to generate permutations
    $('#AnagramTxtArea').append(splitted.join("") + " ");
    t= setInterval(GeneratePermutation(),10);
});
 });

 var AnagramObj = new Anagram();
 function GeneratePermutation() {
        splitted = AnagramObj.NextPermutation(splitted);
        if (splitted!=null)
            $('#AnagramTxtArea').append(splitted.join("") + " ");       
        else  
            $('#StopBtn').click();

    }

and HTML:

<div id="content">
<input id="anagram" type="text" placeholder="Insert your text here" maxlength="80"/>                    <br />
<input id="SubmitBtn" type="submit" value="submit" />
<br />
<textarea id="AnagramTxtArea" readonly="readonly"></textarea>

</div> 

EDIT:
Yet, another problem:

When calling $(‘#StopBtn’).click() code continues to execute after existing the click event function. So i’m in an infinite loop.

  • 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-05-25T03:33:16+00:00Added an answer on May 25, 2026 at 3:33 am

    You need to pass the function object itself to setInterval(), not the result of a call to the function:

    t = setInterval(GeneratePermutation,10);
                                    // ^ No parentheses
    

    EDIT: On your second question, what you can do is check whether the interval is running. If it is, then cancel it:

    var splitted;
    var t;
    $(document).ready(function() {
    $('#SubmitBtn').click(function() {
        if (t !== undefined) { //interval is already running
            clearInterval(t);
            t = undefined;
            $('#SubmitBtn').attr('value','Submit');
        } else {
            //change Start to Stop
            $('#SubmitBtn').attr('value','Stop');
            if ($('#AnagramTxtArea').val().length>0)
                    $('#AnagramTxtArea').text('');
            var inputTxt = $('#anagram').val();
            splitted = inputTxt.split("");
            splitted.sort(); //first sort the array in order to generate permutations
            $('#AnagramTxtArea').append(splitted.join("") + " ");
            t = setInterval(GeneratePermutation,10);
        }
    });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a word-wrap algorithm that basically generates lines of text that fit the
I have an algorithm that generates strings based on a list of input words.
I have to implement an algorithm that generates a timetable for a university. I've
I have implemented an algorithm that will generate unique names for files that will
I have a question, what algorithm can I use to generate a set of
I have an algorithm that recursively makes change in the following manner: public static
I have this algorithm that I want to implement on VB6. Sub Main() dim
If I have an algorithm that takes n log n steps (e.g. heapsort), where
I have a two part question Best-Practice I have an algorithm that performs some
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily

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.