Skip to content
Advertisement

Converting a 1D array to a 2D array

Got an array:

JavaScript

I need to convert it in two dimension:

JavaScript

Below code:

JavaScript

gives the result:

JavaScript

How to get:

JavaScript

Advertisement

Answer

You’re assigning the wrong value to arr[i][j]:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement