Skip to content

Array with holes #497

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

Closed
bkolobara opened this issue Jun 9, 2015 · 1 comment
Closed

Array with holes #497

bkolobara opened this issue Jun 9, 2015 · 1 comment

Comments

@bkolobara
Copy link

I'm looking for a way to have a small array with big hols between the values. E.g.

var list = List([1, 2]);
list = list.set(10000, 3);
list.forEach( x => {
    console.log(x)
});

Expected output should be:

1
2
undefined (printed out once, not 10000)
3

Right now I get the undefined value printed 10000 times. I would like to be still aware that there are holes when traversing the list, but not store all 10000 undefined values inside the Array.

Maybe I would be able to achieve this using another data structure? As I understand it Immutable.js treats lists as trees. When inserting a new value I don't want all the leafs in between. Reversing it should also work.

@bkolobara
Copy link
Author

I solved this by implementing a "sorted map" and checking if I jump over an index when traversing it. It would be really useful if #88 got implemented.

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

No branches or pull requests

2 participants
@bkolobara and others