Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert jagged array to multi-dimension array #26

Open
hctrdev opened this issue Jun 12, 2020 · 0 comments
Open

Convert jagged array to multi-dimension array #26

hctrdev opened this issue Jun 12, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@hctrdev
Copy link
Collaborator

hctrdev commented Jun 12, 2020

Requirement

  • Add a new extension method on jagged arrays (e.g. int[][]) to allow converting them to a multi-dimensional array of the same size (e.g. int[,]). Since the jagged array can have a different number of columns for each row, there should be two options:
    1. Use the size of the smallest row.
    2. Use the size of the largest row and provide a default value for the blank cells.
  • Add tests for the new extension.

Value Proposition

Most of the array extensions in this library use multi-dimensional arrays instead of jagged arrays. Adding this extension would allow easily converting a jagged array to a multi-dimensional array to take advantage of the other extensions this library provides or to serve as a backing array for a OneBasedArray.

Design Ideas

  • Will likely require two methods that will return a multi-dimension array of a different size based on the largest/smallest row in the jagged array
  • First step is to calculate the size of the output array. Either find the largest or the smallest row in the input jagged array and use that for the second dimension of the output array.
  • Will probably need to be implemented with two for-loops that iterate over the jagged array and build the new multi-dimensional array as they go.
    • If the cell is inside the bounds of the jagged array, copy over the value
    • If the cell is outside the bounds of the jagged array, use the provided default value
  • Possibly add a third method that takes maxColumn and maxRow variables that define the size of the output array. When creating the array, if there is no corresponding location in the jagged array, use the default value.
@hctrdev hctrdev added the enhancement New feature or request label Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant