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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:40:40+00:00 2026-05-26T11:40:40+00:00

I currently have a 2 dimensional array that has data like this : X

  • 0

I currently have a 2 dimensional array that has data like this :

    X   X   X       X
    X   X   X       X
        X       X   X
        X   X   X   X
    X   X       X   X
    X   X   X   X   X

X marks a cell that has data, blank means its empty.
I having been pulling my hair for the last hour trying to figure out how to count what I call “holes”.
It’s basically a cell with empty data between two cells having data.
So by order you can see the cols have respectively 2, 0, 2, 0, 0 holes from left to right.
My function needs to return the total holes, so for this case 4.

Currently I have done this really close but my function is counting the 2 first cells on the 4th col which is wrong and I can’t figure out how to account for that.

Here is my actual code :

public function countHoles(){
        $total = 0;
        for($i=0; $i<5; $i++){
            $counting = false;
            $passed = false;
            for($j=0; $j<10; $j++){
                if(count($this->table[$j][$i])>0){
                    $passed = true;
                }
                if($passed && !$counting && count($this->table[$j][$i])==0){
                    $counting = true;
                }
                else{
                    $counting = false;
                }
                if($passed && $counting){
                    $total++;
                }
            }
        }
        return $total;
    }

Your help is appreciated.

  • 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-26T11:40:40+00:00Added an answer on May 26, 2026 at 11:40 am

    I have an answer in javascript, try this:

    var arr = [[1,2,3,null,5],[1,2,3,null,5],[null,2,null,null,5],[null,2,3,4,null],[1,null,null,4,5],[1,2,3,4,null]];  
    var hole = 0;   
    for(var i=0; i<arr.length; i++){        
        for(var j=1; j<arr[i].length-1; j++){
            if(arr[i][j]==null){
                for(var k=j;k<arr[i].length; k++){
                    if(arr[i][k] != null){
                        k = arr[i].length;
                    }else{
                        j++;                        
                    }
                }
                if(j < arr[i].length){                  
                    hole++;
                }
            }
        }
    }
    alert(hole);
    

    ‘hole’ is the var with the number of holes

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

Sidebar

Related Questions

We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
I currently have a DetailsView in ASP.NET that gets data from the database based
I have a 1-dimensional array that fills up a table of 40 random elements
and thanks for looking. I have a 2D c# array, that has 50 as
Say you have the following ANSI C code that initializes a multi-dimensional array :
I have a very specific problem here. I have a multi-dimensional array that I
I have a multi dimensional array with 200 keys and each key has 3
I have a multi-dimensional array that I am trying to feed into difflib.get_close_matches() .
I have a numpy one dimensional array c that is supposed to be filled
So I have a 2-dimensional array representing a coordinate plane, an image. On that

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.