impatient-js icon indicating copy to clipboard operation
impatient-js copied to clipboard

Chapter: Arrays (`Array`)

Open rauschma opened this issue 6 years ago • 8 comments

rauschma avatar Jul 12 '18 17:07 rauschma

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

Flooorent avatar Feb 26 '19 10:02 Flooorent

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

rauschma avatar Mar 23 '19 17:03 rauschma

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.

ivansvlv avatar May 31 '19 06:05 ivansvlv

@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' ]

rauschma avatar May 31 '19 07:05 rauschma

@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!

ivansvlv avatar May 31 '19 07:05 ivansvlv

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

wgmyers avatar Oct 05 '20 02:10 wgmyers

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

YSternlicht avatar Oct 19 '20 12:10 YSternlicht

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

rauschma avatar Feb 03 '21 07:02 rauschma