Array in javascript

V

VK

Richard said:
You can always specuatle.

That was not anything personal, just a side note for possible readers.
Where dynamicsness is a fundamental characteristic of a javascript
Array. all arrays may be subject to runtime modification.

*May* - but don't have to. But this attribute is used to define this
particular array model.
Where sparseness is a fundamental characteristic of a javascript Array.
all javascript arrays either are sparse or can be rendered sparse.

*Can* - but don't have to. But this attribute is used to define this
particular array model.

var arr = new Array(1,2,3);
// Currently it's not a sparse array
// It's a condensed array (and please - it is not
// "another of VK's proprietary terms", OK?)
// the only personal term I ever used was "psi-link"
arr[1000] = 4;
// Now it's a sparse array

That doesn't really mean anything.

Don't cheat now ;-)
All javascript Arrays are single-dimensional, that is also a
characteristic of the javascript Array.

Jagged array is Array Of Arrays. Note the number of the first noun:
it's sungular. Array (one) Of Arrays - not Multidimensional array. Very
important attribute used in the model description.

var arr = [[2,3],[6,5],[0,9]];
This array has evenly sized "pseudo-dimensions" but it's still
*jagged*, not multidimensional. It's still really a sinle-dimension
array, you still can do things you can do only with jagged array like:

function byNumbers(a,b) {return a-b;}
arr.sort(byNumbers);
 
J

John G Harris

Some sources also suggest to use "multi-typed" as indication of
possibility to have elements of different types in the array. I do not
stay for it as it seems formally incorrect to say "multi-typed" in a
type loose language.

You are cheating when you say that. Javascript has clearly defined
types. If an Array object has some objects that are Array objects and
some that are not then you have the general case, which is where you
should be starting from. The classification of structures built from
Array objects and non-Array elements then goes as follows :

a) Tree.
General case.
Array objects provide the links to subtrees.

b) Some trees are also n-dimensional arrays.
Their leaf nodes are all at the same depth.

c) Some n-dimensional arrays are also regular. I.e not jagged.
Array objects at the same depth all have the same length.

d) Some regular n-dimensional arrays also have the same type at all the
leaf nodes. E.g All are Numbers.
This is a common case in javascript programs.

John
 
R

Richard Cornford

VK said:
Richard Cornford wrote:

*May* - but don't have to. But this attribute is used to
define this particular array model.

Dynamic is not "used to define this particular array model", it is a
characteristic of javascript Arrays in general.
*Can* - but don't have to. But this attribute is used to
define this particular array model.

Sparse is not "used to define this particular array model", it is a
characteristic of javascript Arrays in general; all javascript arrays
can be rendered sparse (as a consequence of having the potential to be
sparse combined with being dynamic).
var arr = new Array(1,2,3);
// Currently it's not a sparse array
// It's a condensed array (and please - it is not
// "another of VK's proprietary terms", OK?)
// the only personal term I ever used was "psi-link"

You do, however, apply many terms inappropriately (or just employ them
in nonsensical contexts).
arr[1000] = 4;
// Now it's a sparse array

That doesn't really mean anything.

Don't cheat now ;-)

I am not cheating. that is a statement that is insufficient to say
anything, and in saying nothing it also means nothing.
Jagged array is Array Of Arrays.

And an array of arrays is a construct built with arrays.
Note the number of the first noun:
it's sungular. Array (one) Of Arrays - not Multidimensional
array.

And the "Arrays" is plural, making the construct something that is not
an Array.
Very important attribute used in the model description.

var arr = [[2,3],[6,5],[0,9]];

A javascript Array initialiser that has three more javascript Array
initialisers defining the elements of the first array (total of 4
Arrays).
This array has evenly sized "pseudo-dimensions" but it's
still *jagged*, not multidimensional.

It has more than one dimension and you consider that as not being
multi-dimensional?
It's still really a sinle-dimension array,

"It" is not "a single dimension array", "it" is a construct made with
four javascript Arrays. "It" is a construct to which the label 'jagged
array' can be applied as it satisfies the quoted definitions, but "it"
is not a javascript Array.
you still can do things you can do only with jagged array
like:

Fine, but "it" is _not_ a javascript Array so what it is, and whatever
can be done with it, does not transfer qualities on to javascript
Arrays.
function byNumbers(a,b) {return a-b;}
arr.sort(byNumbers);

Wouldn't it be an ides, just occasionally, to test code before you post
it?

Richard.
 
T

Thomas 'PointedEars' Lahn

Richard said:
Wouldn't it be an ides, just occasionally, to test code before you post
it?

I do not understand what you mean by that. The posted source code certainly
sorts the array elements of the array encapsulated by `arr' according to the
numerical greater-than relation. `byNumbers' is one of the simplest and
most efficient comparators possible.


PointedEars
 
R

Richard Cornford

Thomas said:
I do not understand what you mean by that. The posted source
code certainly sorts the array elements of the array encapsulated
by `arr' according to the numerical greater-than relation.
`byNumbers' is one of the simplest and most efficient comparators
possible.

No it doesn't. On IE 6 it produces a "Number Expected" error.

Arrays inherit their valueOf methods from Object.prototype, which
returns the - this - value of the object. The - this - value is not
primitive so the type-conversion to number process will call toString on
the arrays (see the definition of [[DefaultValue]]) and then convert
those values to a number, where the result will likely be Numeric NaN
(because of the commas in the string value of an array), which will
hardly enable meaningful sorting of the array.

The value returned from the comparison function is expected to be a
non-NaN number (Section 15.4.4.11) and so an error reading 'Number
Expected" when the result is Not a Number (NaN) is correct and
informative when the comparison function does return NaN.

Richard.
 
T

Thomas 'PointedEars' Lahn

Richard said:
No it doesn't.

Yes, it does. But not for /this/ Array object :)
On IE 6 it produces a "Number Expected" error. [...]

I now see you are referring to the initialized value of `arr' explicitly:

| var arr = [[2,3],[6,5],[0,9]];

Yes, of course, with /that/ value (i.e. a "two-dimensional array"; sorry, I
know no better concise expression, maybe you can enlighten me) the sorting
does not work as supposed in Gecko-based UAs and Opera 8.51/Linux as well;
however, there is no error (and no warning).

Interestingly, Gecko-based UAs return the expected "2,3,6,5,0,9" while Opera
returns "0,9,6,5,2,3" as string representation of the Array object [without
modifying Array.prototype.toString() before.]


PointedEars
 
V

VK

var arr = [[2,3],[6,5],[0,9]];

function byNumbers(a,b) {return a[1]-b[1];}

arr2 = arr.sort(byNumber);

By context (if you understand what jagged array is and how does it
differ from a multidimensional one) one could see the typo.

No need to post so many useless words instead.
 
R

Richard Cornford

Thomas said:
^^^^^^^^


Yes, it does. But not for /this/ Array object :)

But it was this array that the posted code was trying to sort. And I had
assumed that when you said "sorts the array elements of the array
encapsulated by `arr'" that you were referring to the same array.
On IE 6 it produces a "Number Expected" error. [...]

I now see you are referring to the initialized value of `arr'
explicitly:

Yes, I am hardly likely to maintain that arrays cannot be sorted, or
even that the array in question cannot be sorted, just that the code VK
posted and stated would work does not do anything useful when it doesn't
error and does error-out on the most common web browser in use.
| var arr = [[2,3],[6,5],[0,9]];

Yes, of course, with /that/ value (i.e. a "two-dimensional array";
sorry, I know no better concise expression, maybe you can enlighten
me)

I don't have any problem with labelling that construct as a
two-dimensional array.
the sorting does not work as supposed in Gecko-based UAs and
Opera 8.51/Linux as well;

The specification doesn't say how it is supposed to work when the
comparison function does not meet the requirements of the specification
(to return a non-NaN number).
however, there is no error (and no warning).

The interpreter's response to the flawed comparison function is not
specified so any behaviour, from erroring to silence, is acceptable.
Interestingly, Gecko-based UAs return the expected "2,3,6,5,0,9"
while Opera returns "0,9,6,5,2,3" as string representation of the
Array object [without modifying Array.prototype.toString() before.]

As the actual sorting algorithm is not specified it would be possible
for every implementation to use a different algorithm, with a different
outcome when the values returned from the comparison function are
essentially meaningless.

Richard.
 
R

Richard Cornford

VK said:
var arr = [[2,3],[6,5],[0,9]];

function byNumbers(a,b) {return a[1]-b[1];}

arr2 = arr.sort(byNumber);

By context (if you understand what jagged array is and how
does it differ from a multidimensional one) one could see
the typo.

No need to post so many useless words instead.

That is completely irrelevant to the message you have responded to
(Which was Message-ID: [email protected]).

But if you are embraced by posting code that does not work you can avoid
the condition by doing no more than testing it before you post it. It
would help if you started with the realisation that you are not at all
good at javascript and cannot trust the untested products of you mind to
be correct.

Richard.
 
V

VK

Richard said:
Yes, I am hardly likely to maintain that arrays cannot be sorted, or
even that the array in question cannot be sorted, just that the code VK
posted and stated would work does not do anything useful when it doesn't
error and does error-out on the most common web browser in use.

God damn it was an after-midnight typo, sorry again.

var arr = [[3,2],[4,3],[6.7]];

function by2nd(a,b) {
return a-b;
}

var arr2 = arr.sort(by2nd);

P.S. Yes it requires extra code for string values
P.P.S. Yes it requires extra code for mixed values

I hope though that the intended idea is expressed clearly now.

If you still need more explanations what "jagged" and
"multidimensional" arrays are and why they are not the same, I will try
to help.
 
R

Richard Cornford

VK said:
God damn it was an after-midnight typo, sorry again.

It was not a typo, it was technically uninformed code posted in the
arrogant and misguided belief that what comes out of your mind has some
relationship to javascript. Typos are minor mistakes in code that would
work otherwise not the use of completely inappropriate expressions.
var arr = [[3,2],[4,3],[6.7]];

function by2nd(a,b) {
return a-b;
}

var arr2 = arr.sort(by2nd);

P.S. Yes it requires extra code for string values

And did you test that code? "Number Expected" again, you just don't take
good advice do you? Didn't I mention that everyone makes mistakes but it
takes a real fool to repeat them?
P.P.S. Yes it requires extra code for mixed values

I don't think so, it will error-out just as quickly with any value type
in the inner arrays.
I hope though that the intended idea is expressed clearly now.

That doesn't matter as what you have clearly expressed is probably more
informative in context.
If you still need more explanations what "jagged" and
"multidimensional" arrays are and why they are not the same,

Not why they are not the same but why you think one is applicable to an
array of arrays and the other is not.
I will try to help.

You could help by actually answering the original question and explain
how a quality of a specific type of construct can reasonably be
transferred to the components of that structure, even though those
components are logically incapable of exhibiting that quality at all.

Beyond that there is little help you could offer anyone as your
understanding of javascript is superficial and error-filled and you are
irrational.

Richard.
 
R

Randy Webb

Richard Cornford said the following on 2/13/2006 2:54 AM:
Thomas 'PointedEars' Lahn wrote:

"Array of Arrays"
I don't have any problem with labelling that construct as a
two-dimensional array.

You should as JS doesn't have a two-dimensional array :)

two-dimensional leads to multi-dimensional, neither of which JS possesses.

It's an array of arrays.
 
R

Randy Webb

VK said the following on 2/9/2006 4:38 AM:

Actually it was already answered right away why it is *not*
multi-dimensional array. But as I got more experience in having a
discussion with you, I'm not failing on this trick again. First of all,
dear Sir, you have to find out what *is* multi-dimensional array and
paste (or link) a working sample of multi-dimensional array, say
VBScript, C#, C++ or Java. And this has to come not from your own mind
or a freshly updated wiki article, but *at least* from an engine
producer page or (best of all) from some reputable higher education
establishment.

Let me give you a hint ok? Check it's length property.
Asking for definition while refusing to disclose your own one (so you
can always say: "That's not one!") *was* a great trick, but it is
currently explored to the end - with me at least.

It was no trick. When I ask loaded questions, I give a hint that it is a
loaded question. This was not one. If it were a true multi-dimensional
array, having more than one dimension, being non-linear, then the length
property will tell how many elements are in that array. It fails on
Richards code, and it fails on any "jagged array" code you post.
 
R

Richard Cornford

Randy said:
Richard Cornford said the following on 2/13/2006 2:54 AM:

"Array of Arrays"

A concise expression of something is not necessarily limited to a
literal description of its structure.
You should as JS doesn't have a two-dimensional array :)

Javascript does not have a multi-dimensional Array, but the subject of
the description is a built structure so it is amenable to descriptions
that talk about the nature of the structure that was built. Calling this
structure two-dimensional is a reasonable expression of a characteristic
of the structure as created (it has two dimensions, in one sense).
Calling it an 'array' is also viable, the use of the lower case 'a'
implying the wider English meaning of 'array' rather than the specific
javascript 'Array'.

The actual applicability of any description to any given structure would
depend on why the structure was created. In this case an identical
structure could be implementing a 'tree' concept, where describing the
results as either two-dimensional or an array would be positively
counter-productive as those terms run contrary to the nature of a tree.
two-dimensional leads to multi-dimensional, neither of
which JS possesses.

And both of which may be significant characteristics of structures
created with javascript.
It's an array of arrays.

And it may also be any number of other things in addition. But being an
array of arrays means that it is certainly not a javascript Array.

Richard.
 
R

Randy Webb

Richard Cornford said the following on 2/18/2006 1:04 PM:
A concise expression of something is not necessarily limited to a
literal description of its structure.

That same reasoning can be applied to "jagged array", "hash array", and
"multi-dimensional array". And this entire thread (or most of it anyway)
has been spent on whether JS has a "jagged array" or not.

You can't have it both ways :)
Javascript does not have a multi-dimensional Array, but the subject of
the description is a built structure so it is amenable to descriptions
that talk about the nature of the structure that was built. Calling this
structure two-dimensional is a reasonable expression of a characteristic
of the structure as created (it has two dimensions, in one sense).
Calling it an 'array' is also viable, the use of the lower case 'a'
implying the wider English meaning of 'array' rather than the specific
javascript 'Array'.

So you don't have problems with "jagged array", a "hash array" nor a
"multi-dimensional array" with respect to Javascript as long as the a is
lowercase?

The actual applicability of any description to any given structure would
depend on why the structure was created. In this case an identical
structure could be implementing a 'tree' concept, where describing the
results as either two-dimensional or an array would be positively
counter-productive as those terms run contrary to the nature of a tree.


And both of which may be significant characteristics of structures
created with javascript.


And it may also be any number of other things in addition. But being an
array of arrays means that it is certainly not a javascript Array.

OK, then it is *not* a "two-dimensional array" as JS doesn't possess
one. Again, you can't have it both ways. It is either a cat or a dog,
not both :)

Otherwise, VK is going to bookmark this post and anytime he says JS has
a Jagged/Hash/Multi-Dimensional array and you say it doesn't, he is
going to point back here and say "A concise expression of something is
not necessarily limited to a literal description of its structure."

See the problem now?
 
V

VK

Randy said:
Otherwise, VK is going to bookmark this post and anytime he says JS has
a Jagged/Hash/Multi-Dimensional array and you say it doesn't, he is
going to point back here and say "A concise expression of something is
not necessarily limited to a literal description of its structure."

I already have a whole new bookmark section out of this thread. :)
But keep going - I thought that maybe without my irritating presence
the thinking process would be more productive :)
 
R

Richard Cornford

Randy said:
Richard Cornford said the following on 2/18/2006 1:04 PM:

That same reasoning can be applied to "jagged array",
"hash array", and "multi-dimensional array".

Yes it can, if a construct has been created to implement such concepts
then using such terms as a way of conveying some characteristic of the
construct is quite acceptable. Doing so may not absolutely precise and
may risk introducing wrong associations but it can also be a useful
shortcut to the rapid communication of ideas.
And this entire thread (or most of it anyway) has been spent
on whether JS has a "jagged array" or not.

As I have already said; if javascript can emulate anything then in one
sense it 'has' everything. Trying to apply that definition of javascript
'having' something would most likely inhibit an understanding of what
the javascript language is. A much more reasonable demarcation of what
javascript 'has' would be based on what 'is' by virtue of the nature
language as opposed to what can only be as a result of a construction or
emulation in javascript.

Of your short list only 'hash array' can be applied to something in
javascript without the need for a construction/emulation, as javascript
Objects do have qualities that resemble HashTables, etc. You may recall
that in the past reasonable arguments have been made in favour of
characterising javascript Objects as 'associative arrays' and
'HashTables'. I don't favour those usages as they do seem to directly
result in miss-associations where people expect the javascript Object to
be initially empty, support truly arbitrary keys and (with 'associative
array') have a - length - property that has a relationship with keys
used. But it is also undeniably the case that a value can be stored in a
javascript Object with a property name that can then be used as a key
for the retrieval of that value in the same way as a HashTable may be
used (there a just a stack of caveats that make drawing the parallel
insufficient as an explanation of the javascript Object).
You can't have it both ways :)

And I don't need to. This thread has been about whether it is
appropriate to apply the term 'jagged' to the javascript Array, in the
way that the terms 'dynamic' and 'sparse' can be applied to them.
Arguing that many labels can reasonably be applied to many things even
when those labels do not precisely describe the thing to which they are
attached, when those labels communicate something useful about the
object to which they are attached, is not inconstant with questioning
the applicability of a label to an object that is incapable of
exhibiting the quality named by the label. The javascript Array is
incapable of exhibiting 'jaggedness' so there can be no sense in which
it could be appropriate to characterise the javascript Array as
'jagged'.

The observation that it is possible to create, with javascript,
structures that may reasonably be labelled 'jagged arrays' or, for that
matter, 'multi-dimensional arrays' or 'trees' or 'maps' or whatever,
does not alter the nature of what the javascript Array is and so does
not make it reasonable to apply those labels to it.
So you don't have problems with "jagged array", a "hash array"
nor a "multi-dimensional array" with respect to Javascript as
long as the a is lowercase?

I don't have a problem labelling a structure that satisfies the broad
definition of what an array is as an 'array', and arrays of arrays,
implemented in javascript often satisfy that definition (and javascript
Arrays also satisfy that definition). But because javascript has an
Array constructor with an upper case 'A' it is often felt that using the
upper case 'A' (at least away form the initial letter of a sentence) in
Array should be read as a statement about the special objects of the
type created with the Array constructor. That is; 'Array' should be used
as the name of the type of javascript object and 'array' used to assert
the quaintly of arrayness.

Objects and structures that do not exhibit 'arrayness', and objects that
may exhibit it but only by coincidence (such as trees), probably should
not be labelled as 'arrays'.

OK, then it is *not* a "two-dimensional array" as JS doesn't
possess one.

It is not a two-dimensional Array as javascript Arrays are
single-dimensional. It is a structure than exhibits arrayness and has
two-dimensions (at lest it has two dimensions if you are looking at its
arrayness, if you were looking at its treeness then any number of
dimensions are irrelevant).
Again, you can't have it both ways. It is either a cat
or a dog, not both :)

With a javascript construct what something is depends quite a lot on why
it was created. It could have been created to act as a
'multi-dimensional array', a 'jagged array' or a 'tree'. The same
structure could be any of them so it is up to the author to decide which
concept(s) were intended. Having decided what the concept being
implemented is a set of labels become appropriate to be used to talk
about the qualities of the structure created.
Otherwise, VK is going to bookmark this post and anytime he
says JS has a Jagged/Hash/Multi-Dimensional array and you
say it doesn't, he is going to point back here and say "A
concise expression of something is not necessarily limited
to a literal description of its structure."

VK has already convinced himself that he has won this argument, instead
of just making himself look like an irrational half-whit, so what he may
do in the future will likely be as irrational and irrelevant as his
posts here.
See the problem now?

I can see it, and name it. ;-)

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top