Skip to content

[Chapter 5] Update the matrix function for jagged Arrays#39

Open
AliEl4eikh wants to merge 1 commit into
Apress:masterfrom
AliEl4eikh:patch-1
Open

[Chapter 5] Update the matrix function for jagged Arrays#39
AliEl4eikh wants to merge 1 commit into
Apress:masterfrom
AliEl4eikh:patch-1

Conversation

@AliEl4eikh

Copy link
Copy Markdown

We may loop for the number of rows and create an array with the number of columns, not the opposite.

for (var i=0; i < columns; i +=1) {
jaggedarray[i]=new Array(rows);
}

This loop will work as the columns and rows are equal, But if we want to create a jagged Array with 2 Rows and 3 Columns, this will not give us the expected result

We may loop for the number of rows and create an array with the number of columns, not the opposite.

 for (var i=0; i < columns; i +=1) {
        jaggedarray[i]=new Array(rows);
    }

This loop will work as the columns and rows are equal, But if we want to create a jagged Array with 2 Rows and 3 Columns, this will not give us the expected result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant