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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:49:03+00:00 2026-06-18T23:49:03+00:00

I’m doing this project trying to reproduce Schelling’s Segregation model. I have a function(below)

  • 0

I’m doing this project trying to reproduce Schelling’s Segregation model. I have a function(below) that is testing to see if the four immediate adjacent cells of the array are either the same or different or empty compared to the current cell being tested.

There are four possible spots to be tested for every cell in the array. But on corners and side spots, obviously you cant test spaces that are out of bounds. So in the function, if it finds one of the out of bounds spaces it decrements the number total around the cell. However, it keeps crashing telling me that I have an Uncaught Reference Error: Cannot read property ‘0’ of undefined. I can’t tell why its crashing.

The final lines of this code take the number of goods(similar cells) and the total number of cells around it (empty cells do not count) and gets a percentage similar.

Any help would be appreciated into telling me why it might be crashing and giving me an error? Thanks!

model.Test = function( i, j )
{
var numberToTest= 4;
var goods= 0;

if ((i - 1) >= 0) 
{
    if (model.BoardArray[i-1][j] != "E")
    {
        if (model.BoardArray[i][j] == model.BoardArray[i-1][j])
        {
            goods++;
        }
    }
    else
    {
        numberToTest--;
    }
}
else
{
    numberToTest--;
}


if((i + 1) < $("#BoardSizeValue").val()) 
{
    if (model.BoardArray[i+1][j] != "E")
    {   
        if (model.BoardArray[i][j] == model.BoardArray[i+1][j])
        {
            goods++;
        }
    }
    else
    {
        numberToTest--;
    }
}
else
{
    numberToTest--;
}


if ((j - 1) >= 0) 
{
    if (model.BoardArray[i][j-1] != "E")
    {
        if (model.BoardArray[i][j] == model.BoardArray[i][j-1])
        {
        goods++;
        }
    }
    else
    {
        numberToTest--;
    }
}
else
{
    numberToTest--;
}


if ((j + 1) < $("#BoardSizeValue").val()) 
{
    if (model.BoardArray[i][j+1] != "E")
    {   
        if (model.BoardArray[i][j] == model.BoardArray[i][j+1])
        {
            goods++;
        }
    }
    else
    {
        numberToTest--;
    }
}
else
{
    numberToTest--;
}


var similar = $("#SimilarSlider").val()/100;
if (numberToTest == 0)
{
    return false;
}
else
{
    var needed = goods/numberToTest;

    if (needed >= similar)
    {
        return false;
    }
    else
    {
        return true;
    }
}
}
  • 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-18T23:49:04+00:00Added an answer on June 18, 2026 at 11:49 pm

    From looking at your code, you would only get a Reference Error: Cannot read property '0' of undefined. if i was out of the bounds of the array.

    I think the problem might be in this part of the code:

    if ((i - 1) >= 0) {
        if (model.BoardArray[i-1][j] != "E") {
            if (model.BoardArray[i][j] == model.BoardArray[i-1][j]) {
    

    if i = $("#BoardSizeValue").val() and $("#BoardSizeValue").val() is a one-based index of the array size, then [i-1] would be okay, but not [i]. So try adjusting your code to this:

    if ((i - 1) >= 0 && i < $("#BoardSizeValue").val()) {
        if (model.BoardArray[i-1][j] != "E") {
            if (model.BoardArray[i][j] == model.BoardArray[i-1][j]) {
    

    This would also apply to the j comparisons as well.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this

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.