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

  • Home
  • SEARCH
  • 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 9013375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:15:00+00:00 2026-06-16T03:15:00+00:00

I started making a function that will be able do the following: Count how

  • 0

I started making a function that will be able do the following: Count how many 6 digit numbers you can make with the digits 0,1,2,3,4 and 5, that can be divided by 6?

How I currently try to start, is I make an array of all the possible numbers, then take out every number that has any of the numbers‘ arrays elements in it, then remove the ones that are not dividable with 6.

I got stuck at the second part. I tried making 2 loops to loop in the array of numbers, then inside that loop, create an other one for the length of the allnumbers array to remove all matches.

Then I would use the % operator the same way to get every element out that doesn’t return 0.

The code needs to be flexible. If the user asks for eg. digit 6 too, then the code should still work. Any way I could finish this?

My Code is:

var allnumbers = [],j;
var biggestnumber = "999999999999999999999999999999999999999999999999999999999999";

function howmanynumbers(digits,numbers,divideWith){
    if (digits && numbers && divideWith){
        for (var i = 0; i < 1+Number(biggestnumber.substring(0,digits)); i++ ){
            allnumbers.push(i);
        }

        for (j = 0; j < numbers.length; j++ ){
            var matchit = new RegExp(numbers[j]);
        }
            //not expected to work, I just had this in for reference
        if ( String(allnumbers[i]).match(matchit) != [""]){
            j = 0;
            allnumbers.splice(i,1);
            var matchit = new RegExp(numbers[j])
        }
    }
    else {
        return false;
    }
}
  • 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-16T03:15:01+00:00Added an answer on June 16, 2026 at 3:15 am

    This is my take on the entire solution:

    var i;
    var allowedDigitsPattern = /^[0-5]+$/i;
    var numbers = [];
    
    for (i = 100000; i < 555555; i++) {
        if (allowedDigitsPattern.test(i.toString())
            && i % 6 === 0) {
            numbers.push(i);       
        }
    }
    

    And you can look at your results like this:

    document.write('There are ' + numbers.length + ' numbers<br>');
    
    // write out the first ten!
    for (i = 0; i < 10; i++) {
        document.write(numbers[i] + '<br>');
    }
    

    Update based on comments…

    The configurable version of this would be:

    var i;
    var lowestDigit = 0;
    var highestDigit = 5;
    var numberOfDigits = 6;
    
    var allowedDigitsPattern = new RegExp('^[' + lowestDigit + '-' + highestDigit + ']+$', 'gi');
    
    var smallestNumber = '1';
    for (i = 1; i < numberOfDigits; i++) {
        smallestNumber += '0';
    }
    
    var biggestNumber = '';
    for (i = 0; i < numberOfDigits; i++) {
        biggestNumber += highestDigit.toString();
    }
    
    var numbers = [];
    
    for (i = smallestNumber; i < biggestNumber; i++) {
        if (allowedDigitsPattern.test(i.toString())
            && i % 6 === 0) {
            numbers.push(i);        
        }
    }
    
    document.write('There are ' + numbers.length + ' numbers<br>');
    

    You need to change the smallest and largest numbers based on the configuration. I have made both the allowable digits and the length of the number configurable.

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

Sidebar

Related Questions

Hey, I've just started learning JavaScript and I'm making a little script that generates
I've just started learning Objective-C and made a little compass app that will display
I wish to make a function that checks whether theres any number in the
I started making a reproducible example to ask another question and can't even get
Started making a game. Here's some of my code. package games.tribe.screens; import games.tribe.model.World; import
I started making a very simple application where a list of names is shown
I just started making a database for my website so I am re-reading Database
We recently started making use of the new Google Expansion APK mechanism. Overall it
I have checked out code from a svn repository and started making changes. But
I've recently been learning the MVVM pattern in WPF and just started making my

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.