rauschma / exploring-js

20 stars 0 forks source link

Chapter: Arrays (`Array`) #22

Open rauschma opened 6 years ago

Flooorent commented 5 years ago

There is a typo in the first paragraph of 28.10. Methods: iteration and transformation (.find(), .map(), .filter(), etc.):

we take a look

instead of

we tak a look
rauschma commented 5 years ago

@Flooorent Thanks! Will be fixed in the next release.

ivansvlv commented 5 years ago

31.8.2.1 Creating holes

Either I misunderstood what you are trying to convey here, or there is a false statement:

image

It looks like statement that array.keys() would not reveal empty slot is false, while Object.keys() indeed, wouldn't reveal empty slots:

image

P.S. This difference is presently described in 31.8.2.2 How do Array operations treat holes? and it conflicts with above statement as well.

rauschma commented 5 years ago

@ivansvlv A hole is revealed if you can see that its index is missing. With .keys(), you can’t tell the difference between a hole and an element that is undefined:

> const hole = [,]; const undef = [undefined];
> [...hole.keys()]
[ 0 ]
> [...undef.keys()]
[ 0 ]

With Object.keys(), you can – it reveals the hole:

> Object.keys(hole)
[]
> Object.keys(undef)
[ '0' ]
ivansvlv commented 5 years ago

@ivansvlv A hole is revealed if you can see that its index is missing. With .keys(), you can’t tell the difference between a hole and an element that is undefined:

> const hole = [,]; const undef = [undefined];
> [...hole.keys()]
[ 0 ]
> [...undef.keys()]
[ 0 ]

With Object.keys(), you can – it reveals the hole:

> Object.keys(hole)
[]
> Object.keys(undef)
[ '0' ]

I see, I've misinterpreted "reveal the hole". Sorry for the confusion!

wgmyers commented 4 years ago

Typo in line 6 of remove_empty_lines_push_test.mjs

You have – Similar: remove_empty_lines_push_test.mjs

Should be – Similar: remove_empty_lines_filter_test.mjs

YSternlicht commented 4 years ago

You quote the typescript interface for array like is

interface ArrayLike<T> {
  length: number;
  [n: number]: T;
}

But Array.from({}) works and that has neither property. I know you wrote

// If you omit .length, it is interpreted as 0

but still, Array.from({length:5}) works and returns an array of undefined values. Where is the [n: number]: T; Thanks

rauschma commented 3 years ago

@YSternlicht Arrays can have holes: https://exploringjs.com/impatient-js/ch_arrays.html#array-holes