Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27660 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2015-05-16 02:03 -0700 |
| Last post | 2015-05-17 11:27 +0100 |
| Articles | 20 on this page of 50 — 5 participants |
Back to article view | Back to comp.lang.javascript
Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 02:03 -0700
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 02:10 -0700
MAX_SAFE_INTEGER & MIN_SAFE_INTEGER, was Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 12:03 +0200
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 11:37 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 02:58 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 12:22 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 03:44 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 14:52 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 06:09 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 15:30 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 03:37 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 15:00 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 06:24 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 15:54 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 07:01 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 21:05 +0200
Re: Reverse elements in array, they can be integers or strings. Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-16 23:07 +0000
Re: Reverse elements in array, they can be integers or strings. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-17 00:28 +0100
Re: Reverse elements in array, they can be integers or strings. Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-17 10:37 +0000
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-17 13:34 +0200
Re: Reverse elements in array, they can be integers or strings. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-16 12:01 +0100
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 04:14 -0700
Re: Reverse elements in array, they can be integers or strings. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-16 13:11 +0100
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 06:37 -0700
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 06:54 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 15:58 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 07:04 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 21:16 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 07:51 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 21:25 +0200
Re: Reverse elements in array, they can be integers or strings. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-16 21:41 +0100
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-16 16:51 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-17 11:14 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-17 03:04 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-17 12:40 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-17 06:04 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-17 21:47 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-17 15:06 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-18 00:57 +0200
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-17 17:10 -0700
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-18 13:16 +0200
Re: Reverse elements in array, they can be integers or strings. John Harris <niam@jghnorth.org.uk.invalid> - 2015-05-18 10:28 +0100
Re: Reverse elements in array, they can be integers or strings. Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-18 16:44 +0000
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-18 10:16 -0700
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-18 10:13 -0700
Re: Reverse elements in array, they can be integers or strings. John Harris <niam@jghnorth.org.uk.invalid> - 2015-05-18 19:42 +0100
Re: Reverse elements in array, they can be integers or strings. jonas.thornvall@gmail.com - 2015-05-17 02:58 -0700
Re: Reverse elements in array, they can be integers or strings. Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-16 22:41 +0000
Re: Reverse elements in array, they can be integers or strings. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-16 15:11 +0200
Re: Reverse elements in array, they can be integers or strings. John Harris <niam@jghnorth.org.uk.invalid> - 2015-05-17 11:27 +0100
Page 1 of 3 [1] 2 3 Next page →
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-16 02:03 -0700 |
| Subject | Reverse elements in array, they can be integers or strings. |
| Message-ID | <2ddccd07-49e4-42c3-9ecc-27f047078f84@googlegroups.com> |
I have arrays that are read from right to left, to do arithmetic upon. But at some point i of course want a printout of the elements of the array. So i of course reverse the array, *but* the integer/string elements of course remain reversed. Is there a preferable way to do this, i do understand that i can make a function that reverse the integer/string digit by digit.
[toc] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-16 02:10 -0700 |
| Message-ID | <c2a942a6-90fb-4a44-bd2b-05145c467db3@googlegroups.com> |
| In reply to | #27660 |
Den lördag 16 maj 2015 kl. 11:03:30 UTC+2 skrev jonas.t...@gmail.com: > I have arrays that are read from right to left, to do arithmetic upon. > > But at some point i of course want a printout of the elements of the array. > So i of course reverse the array, *but* the integer/string elements of course remain reversed. > > Is there a preferable way to do this, i do understand that i can make a function that reverse the integer/string digit by digit. A connecting question, maybe.. When i store an integer as an array element it take up 32 bits? But are the characters of a string UTF-8 thus an array element string of 4 characters 32 bits?
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-16 12:03 +0200 |
| Subject | MAX_SAFE_INTEGER & MIN_SAFE_INTEGER, was Re: Reverse elements in array, they can be integers or strings. |
| Message-ID | <XnsA49C7AA25F088eejj99@194.109.133.246> |
| In reply to | #27661 |
jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
Please do not change the subject without starting a new thread.
> When i store an integer as an array element it take up 32 bits?
That is not a question you should ask us.
array elements store variable values,
that can be strings, arrays, objecs of floating-point numbers.
Integer is not a variable type in Javascript.
If you decide to store "integer values" [not "integers"] as Javascript
floating-point numbers, even then the internal "it takes up 32 bits?"
[grammar corrected] is unimportant to you and even might be different for
different Javascript implementations. The only thing you need to know is the
maximum positive and negative integer values allowed:
<script type='text/javascript'>
var N = Number.MAX_SAFE_INTEGER;
document.write(N); // 9007199254740991
document.write('<br>');
document.write(N + 1); // 9007199254740992
document.write('<br>');
document.write(N + 2); // 9007199254740992
document.write('<br>');
document.write( N === Math.pow(2, 53)-1 ); // true
document.write('<br>');
document.write('<br>');
N = Number.MIN_SAFE_INTEGER;
document.write(N); // -9007199254740991
document.write('<br>');
document.write(N - 1); // -9007199254740992
document.write('<br>');
document.write(N - 2); // -9007199254740992
document.write('<br>');
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-16 11:37 +0200 |
| Message-ID | <XnsA49C7649C3FD7eejj99@194.109.133.246> |
| In reply to | #27660 |
jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript: > I have arrays that are read from right to left, to do arithmetic upon. arrays do not have right or left. You again are making up your own terminology. > But at some point i of course want a printout of the elements of the > array. Why "of course"? If you want to print out the inverse of an array: var arrlen = arr.length; for (var i=arrlen;;i--) document.write(arr[i-1]+'<br>'); > So i of course reverse the array, Why "of course"? Reversing an array is a timeconsuming and needless action, as you can easily use a short formula for an inversed index. arr[arrlen-1-i] > *but* the integer/string elements arrays heve elements, the type of content of which do not toutch a reversing. > of course remain reversed. Why "of course"? So you want to change them back, and again consume exponential time? > Is there a preferable way to do this, Yes! Don't reverse physically, manipulate the index. > i do understand that i can make a > function that reverse Well, if you understand that you can do something, it must be okay. I for one don't understand what you mean. > the integer/string digit by digit. You must mean "element by element", arrays don't have digits. Strings too don't have digits, they have characters. You again are making up your own terminology. That is accceptable if you don't pester others with it, but you eventually fall into your own trap, when you will misunderstand the publications of others. ================================ The preferable way is not to inverse long arrays, as, see above and my earlier mail, using an index-manipulation-formula has all the necessary ingredients. Mind that "preferable" depends on what your goals are, if you want unreadable, messy, exponential timeconsuming, buggy and difficult to debug code "of course" your approach might be different. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-16 02:58 -0700 |
| Message-ID | <fdb99a69-c853-4c3a-baca-b2de2d605a12@googlegroups.com> |
| In reply to | #27663 |
Den lördag 16 maj 2015 kl. 11:37:44 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript: > > > I have arrays that are read from right to left, to do arithmetic upon. > > arrays do not have right or left. > You again are making up your own terminology. > > > But at some point i of course want a printout of the elements of the > > array. > > Why "of course"? > > If you want to print out the inverse of an array: > > var arrlen = arr.length; > for (var i=arrlen;;i--) document.write(arr[i-1]+'<br>'); > > > > So i of course reverse the array, > > Why "of course"? > > Reversing an array is a timeconsuming and needless action, > as you can easily use a short formula for an inversed index. > > arr[arrlen-1-i] > > > *but* the integer/string elements > > arrays heve elements, > the type of content of which do not toutch a reversing. > > > of course remain reversed. > > Why "of course"? > So you want to change them back, and again consume exponential time? > > > Is there a preferable way to do this, > > Yes! > > Don't reverse physically, manipulate the index. > > > i do understand that i can make a > > function that reverse > > Well, if you understand that you can do something, it must be okay. > I for one don't understand what you mean. > > > the integer/string digit by digit. > > You must mean "element by element", arrays don't have digits. > Strings too don't have digits, they have characters. > > You again are making up your own terminology. > That is accceptable if you don't pester others with it, > but you eventually fall into your own trap, > when you will misunderstand the publications of others. > > ================================ > > The preferable way is not to inverse long arrays, > as, see above and my earlier mail, > using an index-manipulation-formula has all the necessary ingredients. > > Mind that "preferable" depends on what your goals are, if you want > unreadable, messy, exponential timeconsuming, buggy and difficult to debug > code "of course" your approach might be different. (No i did not mean element by element, i meant what i said. Reverse each element digit by digit) An example Janevert 21 should encode to [1,10] in base eleven because 11+10. But is stored in array as [01,1] Now i want a printout 1,10 And you say i should not physically alter the array at output, and i do not see how it is even possible without touching the array. You could read it into a commaseparated string and reverse that but i doubt that is what you have in mind for efficiency.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-16 12:22 +0200 |
| Message-ID | <XnsA49C7DEB43A7Deejj99@194.109.133.246> |
| In reply to | #27665 |
jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript: > An example Janevert If you cannot even write my name consistently, how the hell do you expect to write consistent code? > 21 should encode to [1,10] in base eleven because 11+10. > But is stored in array as [01,1] If it is stored in an array element, then that array element is an array. > Now i want a printout 1,10 > > And you say i should not physically alter the array at output, and i do > not see how it is even possible I just showed you. If you can invert an array in fact what you are doing is taking the elements of an array according to a index manipulation function [meaning not just from zero to arrlen-1], and then storing each element in another place [in an other array, or maybe swapping elements in the same array] If instead of the whole storing rigmarole, you immediately print that element, why would that not be possible? And when a function internally 'needs' an inverted array, the same is true that the function can use the same index manipulation and so forgo the need of an physically inverted array too. When printing an array, you will have to fetch each element anyway. > without touching the array Again you make up your own newspeak, what the hell is "touching the array"? > You could read it into a commaseparated string and reverse that No, I would not, we were talking about inversing an array before printing it. > but i doubt that is what you have in mind for efficiency. DO NOT INVERT VERY LARGE ARRAYS, AS there is no NEED for that, because it only will cost you time. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-16 03:44 -0700 |
| Message-ID | <774b744c-ddae-4d02-8e8f-a23c7e2d0d63@googlegroups.com> |
| In reply to | #27668 |
Den lördag 16 maj 2015 kl. 12:22:45 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript: > > An example Janevert > > If you cannot even write my name consistently, > how the hell do you expect to write consistent code? > > > 21 should encode to [1,10] in base eleven because 11+10. > > But is stored in array as [01,1] > > If it is stored in an array element, then that array element is an array. > > > Now i want a printout 1,10 > > > > And you say i should not physically alter the array at output, and i do > > not see how it is even possible > > I just showed you. > > If you can invert an array in fact what you are doing is taking the elements > of an array according to a index manipulation function [meaning not just > from zero to arrlen-1], and then storing each element in another place [in > an other array, or maybe swapping elements in the same array] > > If instead of the whole storing rigmarole, you immediately print that > element, why would that not be possible? > > And when a function internally 'needs' an inverted array, the same is true > that the function can use the same index manipulation and so forgo the need > of an physically inverted array too. > > When printing an array, you will have to fetch each element anyway. > > > without touching the array > > Again you make up your own newspeak, what the hell is "touching the array"? > > > You could read it into a commaseparated string and reverse that > > No, I would not, > we were talking about inversing an array before printing it. > > > but i doubt that is what you have in mind for efficiency. > > DO NOT INVERT VERY LARGE ARRAYS, > AS there is no NEED for that, > because it only will cost you time. > > -- I have to be critical Evertjan, what you show do not reverse the digits/characters of the the element, only the order of the element. There is a difference you know. var arrlen = arr.length; for (var i=arrlen;;i--) document.write(arr[i-1]+'<br>'); This code is useless and that is a fact.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-16 14:52 +0200 |
| Message-ID | <XnsA49C974977BB8eejj99@194.109.133.246> |
| In reply to | #27670 |
jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
>> DO NOT INVERT VERY LARGE ARRAYS,
>> AS there is no NEED for that,
>> because it only will cost you time.
>
> I have to be critical Evertjan, what you show do not reverse
See your subject-line:
Re: Reverse elements in array, they can be integers or strings.
So your Q logically is a miswriting of "reverse elements of an array",
but your English is so bad that it now seems you ment
"reversing the content of individual elemnets of an array"
> the digits/characters of the the element,
Elements of an array do not have digits,
elements of an array do not have characters.
Elements of an array have values of one of the types
floating point numeric, string, array or object.
> only the order of the element.
and an element has no order.
> There is a difference you know.
A single element is just like any other variable,
so you could better, much better, have asked:
"how do I reverse the value of a variable?"
Which shows the nonsense of your Q.
> var arrlen = arr.length;
> for (var i=arrlen;;i--) document.write(arr[i-1]+'<br>');
>
> This code is useless and that is a fact.
It is not at all useless,
maybe you should ask that of yourself,
when you ask improperly constructed Qs.
If the content of an element of your array
has the value of an array in itself,
yes then it is possible to invert that array,
and even then it is wasting processor-time to do so,
when printing printing,
as the above function can be rewritten to:
var i, j;
for (j=arr.length;;j--) {
for (i=arr[j].length;;i--)
document.write(arr[j-1][i-1]+';');
document.write('<br>');
};
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-16 06:09 -0700 |
| Message-ID | <21c29a61-19fa-4b40-b9b3-20412cba6aa5@googlegroups.com> |
| In reply to | #27674 |
Den lördag 16 maj 2015 kl. 14:52:23 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
>
> >> DO NOT INVERT VERY LARGE ARRAYS,
> >> AS there is no NEED for that,
> >> because it only will cost you time.
> >
> > I have to be critical Evertjan, what you show do not reverse
>
> See your subject-line:
> Re: Reverse elements in array, they can be integers or strings.
No, no that would be reverse order of elements in array.
*reverse elements* that means there are elements that should be reversed, and they are within an array.
I should have written reverse each integer element within array.
That would be more precise, but i do not think your interpretation of what i wrote is more correct than my.
>
> So your Q logically is a miswriting of "reverse elements of an array",
> but your English is so bad that it now seems you ment
> "reversing the content of individual elemnets of an array"
No i do not think your interpretation hold.
> > the digits/characters of the the element,
>
> Elements of an array do not have digits,
Well since you can look at a digit of an integer i guess they have a prefered digitsize.
> elements of an array do not have characters.
Well if the elements are strings they do have characters.
> Elements of an array have values of one of the types
> floating point numeric, string, array or object.
>
> > only the order of the element.
>
> and an element has no order.
Well strings have the order of characters, and integers have the order of the decimal digits, otherwise you could not look at index of *integer*.
myint.toString()[index];
That is what that function do.
> > There is a difference you know.
>
> A single element is just like any other variable,
> so you could better, much better, have asked:
>
> "how do I reverse the value of a variable?"
No someone would had interpretated that as i wanted to reverse the binary order of the element. So that would not worked.
> Which shows the nonsense of your Q.
>
> > var arrlen = arr.length;
> > for (var i=arrlen;;i--) document.write(arr[i-1]+'<br>');
> >
> > This code is useless and that is a fact.
>
> It is not at all useless,
> maybe you should ask that of yourself,
> when you ask improperly constructed Qs.
>
> If the content of an element of your array
> has the value of an array in itself,
> yes then it is possible to invert that array,
> and even then it is wasting processor-time to do so,
> when printing printing,
> as the above function can be rewritten to:
>
> var i, j;
> for (j=arr.length;;j--) {
> for (i=arr[j].length;;i--)
> document.write(arr[j-1][i-1]+';');
> document.write('<br>');
> };
>
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-16 15:30 +0200 |
| Message-ID | <XnsA49C9DC58F066eejj99@194.109.133.246> |
| In reply to | #27676 |
jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
> Den lördag 16 maj 2015 kl. 14:52:23 UTC+2 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
>>
>> >> DO NOT INVERT VERY LARGE ARRAYS,
>> >> AS there is no NEED for that,
>> >> because it only will cost you time.
>> >
>> > I have to be critical Evertjan, what you show do not reverse
>>
>> See your subject-line:
>> Re: Reverse elements in array, they can be integers or strings.
>
> No, no that would be reverse order of elements in array.
>
> *reverse elements* that means there are elements that should be
> reversed, and they are within an array.
>
> I should have written reverse each integer element within array.
No, you cannot reverse integer elements, I hope you mean "integer values
stored in an element of an array", you can only reverse the elements of an
array [and the characters of a string].
[One can inverse an integer]
> That would be more precise,
No, it is downright wrong.
> but i do not think your interpretation of
> what i wrote is more correct than my.
No, my interpretation is that what you wrote is downright wrong.
>> So your Q logically is a miswriting of "reverse elements of an array",
>> but your English is so bad that it now seems you ment
>> "reversing the content of individual elemnets of an array"
>
> No i do not think your interpretation hold.
Then we would be at a loss of what you ment, wouldn't we?
>> > the digits/characters of the the element,
>>
>> Elements of an array do not have digits,
>
> Well since you can look at a digit of an integer
No, integers do not have digits, only string representations of such
integers can have characters having individal intrinsic and sometimes
positional values.
> i guess they have a prefered digitsize.
A "prefered digitsize", what the hell is that?
>> elements of an array do not have characters.
>
> Well if the elements are strings they do have characters.
The elements "are" not strings, strings can be stored in an element,
or even better, the value of an element can be a string-value.
>> Elements of an array have values of one of the types
>> floating point numeric, string, array or object.
>>
>> > only the order of the element.
>>
>> and an element has no order.
> Well strings have the order of characters, and integers have the order
> of the decimal digits, otherwise you could not look at index of
> *integer*. myint.toString()[index];
An integer can be stored and written in the form of a string-representation,
but the integer itself is a special numeric *value*.
So integers have no indexes.
> That is what that function do.
Sorry?
>> > There is a difference you know.
>>
>> A single element is just like any other variable,
>> so you could better, much better, have asked:
>>
>> "how do I reverse the value of a variable?"
>
> No someone would had interpretated that as i wanted to reverse the
> binary order of the element. So that would not worked.
Elements have no binary order,
they are places where values are stored in one of the available types.
Such value if it is a floating point type, can be thought of as a binary
number an manipulated bitwize if the value is integer within certain
bounderies.
Or do you mean by "binary order" sometinh like just up or down?
>> Which shows the nonsense of your Q.
>>
>> > var arrlen = arr.length;
>> > for (var i=arrlen;;i--) document.write(arr[i-1]+'<br>');
>> >
>> > This code is useless and that is a fact.
>>
>> It is not at all useless,
>> maybe you should ask that of yourself,
>> when you ask improperly constructed Qs.
>>
>> If the content of an element of your array
>> has the value of an array in itself,
>> yes then it is possible to invert that array,
>> and even then it is wasting processor-time to do so,
>> when printing printing,
>> as the above function can be rewritten to:
>>
>> var i, j;
>> for (j=arr.length;;j--) {
>> for (i=arr[j].length;;i--)
>> document.write(arr[j-1][i-1]+';');
>> document.write('<br>');
>> };
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-16 03:37 -0700 |
| Message-ID | <fafb0168-4124-415e-9f02-7775f0256619@googlegroups.com> |
| In reply to | #27665 |
Den lördag 16 maj 2015 kl. 11:58:18 UTC+2 skrev jonas.t...@gmail.com:
> Den lördag 16 maj 2015 kl. 11:37:44 UTC+2 skrev Evertjan.:
> > jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
> >
> > > I have arrays that are read from right to left, to do arithmetic upon.
> >
> > arrays do not have right or left.
> > You again are making up your own terminology.
> >
> > > But at some point i of course want a printout of the elements of the
> > > array.
> >
> > Why "of course"?
> >
> > If you want to print out the inverse of an array:
> >
> > var arrlen = arr.length;
> > for (var i=arrlen;;i--) document.write(arr[i-1]+'<br>');
> >
> >
> > > So i of course reverse the array,
> >
> > Why "of course"?
> >
> > Reversing an array is a timeconsuming and needless action,
> > as you can easily use a short formula for an inversed index.
> >
> > arr[arrlen-1-i]
> >
> > > *but* the integer/string elements
> >
> > arrays heve elements,
> > the type of content of which do not toutch a reversing.
> >
> > > of course remain reversed.
> >
> > Why "of course"?
> > So you want to change them back, and again consume exponential time?
> >
> > > Is there a preferable way to do this,
> >
> > Yes!
> >
> > Don't reverse physically, manipulate the index.
> >
> > > i do understand that i can make a
> > > function that reverse
> >
> > Well, if you understand that you can do something, it must be okay.
> > I for one don't understand what you mean.
> >
> > > the integer/string digit by digit.
> >
> > You must mean "element by element", arrays don't have digits.
> > Strings too don't have digits, they have characters.
> >
> > You again are making up your own terminology.
> > That is accceptable if you don't pester others with it,
> > but you eventually fall into your own trap,
> > when you will misunderstand the publications of others.
> >
> > ================================
> >
> > The preferable way is not to inverse long arrays,
> > as, see above and my earlier mail,
> > using an index-manipulation-formula has all the necessary ingredients.
> >
> > Mind that "preferable" depends on what your goals are, if you want
> > unreadable, messy, exponential timeconsuming, buggy and difficult to debug
> > code "of course" your approach might be different.
>
> (No i did not mean element by element, i meant what i said. Reverse each element digit by digit)
>
> An example Janevert
>
> 21 should encode to [1,10] in base eleven because 11+10.
> But is stored in array as [01,1]
>
> Now i want a printout 1,10
>
> And you say i should not physically alter the array at output, and i do not see how it is even possible without touching the array. You could read it into a commaseparated string and reverse that but i doubt that is what you have in mind for efficiency.
This is what i can come up with, is it correct and fast enough?
var myArr=[01,1];
var printStr="";
reverse_array(myArr);
function reverse_array(thisArr){
var arrLength;
arrLength=thisArr.length;
for (i=arrLength;i>=0;i--){
thisElement=thisArr[i];
reverse_element(thisElement);
}
}
function reverse_element(element) {
index=element.length;
while(index > 0) {
index=index-1;
printStr=+element.toString()[index];
}
}
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-16 15:00 +0200 |
| Message-ID | <XnsA49C98B56DF71eejj99@194.109.133.246> |
| In reply to | #27669 |
jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
> var arrLength;
> arrLength=thisArr.length;
var arrLength = thisArr.length;
> for (i=arrLength;i>=0;i--){
for (i=arrLength;;i--){
> thisElement=thisArr[i];
this will give an ERROR,
as the highest indexed element has an index of i-1
> reverse_element(thisElement);
You cannot reverse an element, you can reverse the CONTENT of an element and
then only when it is an array, [or perhaps a string], and then it does not
matter whether such array is a member of an array or a simple variable.
So your naming of that function is terribly wrong and consequentally buggy.
However: DO NOT REVERSE ARRAYS, manipulate the index.
> }
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-16 06:24 -0700 |
| Message-ID | <e236cda1-5c94-4518-a957-885b08f3983b@googlegroups.com> |
| In reply to | #27675 |
Den lördag 16 maj 2015 kl. 15:01:31 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
>
> > var arrLength;
> > arrLength=thisArr.length;
>
> var arrLength = thisArr.length;
>
> > for (i=arrLength;i>=0;i--){
>
> for (i=arrLength;;i--){
>
> > thisElement=thisArr[i];
>
> this will give an ERROR,
> as the highest indexed element has an index of i-1
>
> > reverse_element(thisElement);
>
> You cannot reverse an element, you can reverse the CONTENT of an element and
> then only when it is an array, [or perhaps a string], and then it does not
> matter whether such array is a member of an array or a simple variable.
Well i wanted to reverse both the array and the element.
And i do not think that reverse an integer is a defined operation.
Would it mean to reverse it at binary level, ternary or what?
If you revese it at binary level it hardly show up as one expected.
You want to reverse the members of the element, but what is the size of the members. *They are of digit size* and since you can reach an index within integer. Since the function to.String()[index] actually assume that you want to look at decimal digits.
I think at least i concure that those digits stored at each index *are assumed decimal*
>
> So your naming of that function is terribly wrong and consequentally buggy.
>
> However: DO NOT REVERSE ARRAYS, manipulate the index.
>
>
> > }
> >
>
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-16 15:54 +0200 |
| Message-ID | <XnsA49CA1CCDD4F7eejj99@194.109.133.246> |
| In reply to | #27678 |
jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript: > Well i wanted to reverse both the array and the element. You cannot reverse an element. You can reverse the value of an element, if the value is of the type array [or string], but the procedure would be the same as for a value stored in a simple variable. > And i do not think that reverse an integer is a defined operation. You cannot reverse an integer, an integer is a numeric value. > Would it mean to reverse it at binary level, ternary or what? An integer has no levels in that sense. > If you revese it at binary level it hardly show up as one expected. So what you say has no meaning whatever. > You want to reverse the members of the element, Elements have no members. Elements and members have the same meaning in the sense of an array. In an element an array can be stored having elements of its own: var resultingValue = arr[outerIndex][innerIndex]; > but what is the size of the members. *They are of digit size* No, members [=elements] of an array contain only values of one of the available types. "digit-size" is not a value. > and since you can reach an index within integer. No, you cannot "reach" [whatever that is] that because integers are numeric values, and numeric values have no internal indexes. Ask yourself: "What is the index of the value 2 and how can I reach that?" > Since the function to.String()[index] actually assume > that you want to look at decimal digits. functions do not assume anything, and functions do not know what you want. > I think I hope so > at least i concure Concur [=agree] with whom? With yourself, I presume. > that those digits stored at each index they are stored at the members or elements of an array, not at an index, the index being the pointer to such member/element. You cannot store digits, as digits are not values of one of the aviable types, and even so, what do you mena by digits here? > *are assumed decimal* Well, you can assume what you like, but as I said, functions don't assume. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-16 07:01 -0700 |
| Message-ID | <c828c8d2-3707-4152-856b-50693f1b0fc2@googlegroups.com> |
| In reply to | #27681 |
Den lördag 16 maj 2015 kl. 15:54:30 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript: > > > Well i wanted to reverse both the array and the element. > > You cannot reverse an element. > > You can reverse the value of an element, > if the value is of the type array [or string], > but the procedure would be the same as for > a value stored in a simple variable. > > > And i do not think that reverse an integer is a defined operation. > > You cannot reverse an integer, an integer is a numeric value. > > > Would it mean to reverse it at binary level, ternary or what? > > An integer has no levels in that sense. > > > If you revese it at binary level it hardly show up as one expected. > > So what you say has no meaning whatever. > > > You want to reverse the members of the element, > > Elements have no members. Janevert sometime you are so tedious, an integer number do have the members of its digits. If you have a javascript form field and write in number 0123456789 that number do have the members 0,1,2,3,4,5,6,7,8,9 eachone is a *decimal* digit. Do you really question that? It is another question altogether that those are created due to base 10 partitioning. But those are digits and members of the number. > > Elements and members have the same meaning in the sense of an array. > > In an element an array can be stored having elements of its own: > > var resultingValue = arr[outerIndex][innerIndex]; > > > but what is the size of the members. *They are of digit size* > > No, members [=elements] of an array contain only values of one of the > available types. > > "digit-size" is not a value. > > > and since you can reach an index within integer. > > No, you cannot "reach" [whatever that is] that because integers are > numeric values, and numeric values have no internal indexes. > > Ask yourself: > "What is the index of the value 2 and how can I reach that?" > > > Since the function to.String()[index] actually assume > > that you want to look at decimal digits. > > functions do not assume anything, > and functions do not know what you want. > > > I think > > I hope so > > > at least i concure > > Concur [=agree] with whom? > With yourself, I presume. > > > that those digits stored at each index > > they are stored at the members or elements of an array, > not at an index, the index being the pointer to such member/element. > > You cannot store digits, > as digits are not values of one of the aviable types, > and even so, what do you mena by digits here? > > > *are assumed decimal* > > Well, you can assume what you like, > but as I said, functions don't assume. > > > -- > Evertjan. > The Netherlands. > (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-16 21:05 +0200 |
| Message-ID | <XnsA49CD6981C367eejj99@194.109.133.246> |
| In reply to | #27684 |
jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript: > Janevert Your naming conventions are douwnright wrong ans so offensive, Jason. > sometime you are so tedious, No, I am just trying to lean you some logic. Programming without logic is doomed to fail. > an integer number do have the members of its digits. No, [besides that this is incomprehensable Engish], integer numbers have no digits [and no base], they are just numeric values. Only their sting representations have digits, and only these string represtentations need a base value. [The base value also only being an integer] > If you have a javascript form field and write in number 0123456789 that > number That is not a number, the form input field contains a string. > do have the members 0,1,2,3,4,5,6,7,8,9 eachone is a *decimal* > digit. They are not members, they are characters typed in the said field. They are dot neccessarily to be interpreted as base-10 digits, the characters could be interpreted as bas-7 or base-36 [some characters would be invalid in some bases like the character 'b' in base-10.] This interprtation is up to the programmer, but the text input is a string. > Do you really question that? I do not, you are simply wrong. > It is another question altogether that those are created due to base 10 > partitioning. No they are not created "due to" anything, they are just typed into the input form field defaulting to type=text. > But those are digits and members of the number. In your dreams. In fact they are just characters of a string. Numbers are values, Javascript numbers are [stored as] floating-point values, numbers themselves have no base. Integers are a subset of all numbers, Javascript integers are [stored as] floating-point values. You can yourself write an integer as a string in many ways: like "three hundred fifty one", but that does not influence the value of such integer. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-05-16 23:07 +0000 |
| Message-ID | <mj8ik2$f1c$4@dont-email.me> |
| In reply to | #27675 |
On Sat, 16 May 2015 15:00:42 +0200, Evertjan. wrote:
> jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
>> var arrLength;
>> arrLength=thisArr.length;
>> for (i=arrLength;i>=0;i--){
>> thisElement=thisArr[i];
> this will give an ERROR,
> as the highest indexed element has an index of i-1
Will it?
Given i starting at thisArr.length and executing an i-- before accessing
the array, I don't think it will give that error, the error will be on
the pass after i == 0, as it will then decrement i and execute the loop
with i having a value of -1, which is an illegal array index.
All of the following are valid in c-type languages where 0 is "falsey",
numbers other than 0 are "truthy" and arrays are 0 indexed:
for (var i = arr.length; i > 0; i--) {
// do something with arr[i]
}
for (var i = arr.length; i; i--) {
// do something with arr[i]
}
var i = arr.length;
while (i--) {
// do something with arr[i]
}
and will walk through the array from element arr[arr.length-1] to element
arr[0].
In the for loops, you can also use prefix style decrement, eg --i as the
third element of the for expression, however you can not do that when
using the while loop, as it causes the loop execution to terminate one
iteration early.
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-17 00:28 +0100 |
| Message-ID | <87lhgom7ah.fsf@bsb.me.uk> |
| In reply to | #27702 |
Denis McMahon <denismfmcmahon@gmail.com> writes:
> On Sat, 16 May 2015 15:00:42 +0200, Evertjan. wrote:
>
>> jonas.thornvall@gmail.com wrote on 16 mei 2015 in comp.lang.javascript:
>
>>> var arrLength;
>>> arrLength=thisArr.length;
>>> for (i=arrLength;i>=0;i--){
>>> thisElement=thisArr[i];
>
>> this will give an ERROR,
>> as the highest indexed element has an index of i-1
>
> Will it?
The code is wrong, but whether it "gives and ERROR" depends on what
was meant by that.
> Given i starting at thisArr.length and executing an i-- before accessing
> the array, I don't think it will give that error, the error will be on
> the pass after i == 0, as it will then decrement i and execute the loop
> with i having a value of -1, which is an illegal array index.
You've got the place where the decrement happens mixed up -- it is done
after each execution of the loop body, so the loop above initially
accesses an undefined element, and then accesses all of the defined
elements in sequence. An index of -1 is not used (though i == -1 at the
end of the loop's execution).
> All of the following are valid in c-type languages where 0 is "falsey",
> numbers other than 0 are "truthy" and arrays are 0 indexed:
>
> for (var i = arr.length; i > 0; i--) {
> // do something with arr[i]
> }
>
> for (var i = arr.length; i; i--) {
> // do something with arr[i]
> }
No, these are both wrong. They access an undefined element first, and
neither accesses element 0.
> var i = arr.length;
> while (i--) {
> // do something with arr[i]
> }
This one is correct.
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-05-17 10:37 +0000 |
| Message-ID | <mj9r1a$ods$1@dont-email.me> |
| In reply to | #27703 |
On Sun, 17 May 2015 00:28:22 +0100, Ben Bacarisse wrote:
> Denis McMahon <denismfmcmahon@gmail.com> writes:
>
>> On Sat, 16 May 2015 15:00:42 +0200, Evertjan. wrote:
>>
>>> jonas.thornvall@gmail.com wrote on 16 mei 2015 in
>>> comp.lang.javascript:
>>
>>>> var arrLength; arrLength=thisArr.length; for (i=arrLength;i>=0;i--){
>>>> thisElement=thisArr[i];
>>
>>> this will give an ERROR,
>>> as the highest indexed element has an index of i-1
>>
>> Will it?
>
> The code is wrong, but whether it "gives and ERROR" depends on what was
> meant by that.
>
>> Given i starting at thisArr.length and executing an i-- before
>> accessing the array, I don't think it will give that error, the error
>> will be on the pass after i == 0, as it will then decrement i and
>> execute the loop with i having a value of -1, which is an illegal array
>> index.
>
> You've got the place where the decrement happens mixed up -- it is done
> after each execution of the loop body, so the loop above initially
> accesses an undefined element, and then accesses all of the defined
> elements in sequence. An index of -1 is not used (though i == -1 at the
> end of the loop's execution).
HeadDesk! Doh, yeah, apologies to Evertjan.
>> All of the following are valid in c-type languages where 0 is "falsey",
>> numbers other than 0 are "truthy" and arrays are 0 indexed:
>>
>> for (var i = arr.length; i > 0; i--) {
>> // do something with arr[i]
>> }
>>
>> for (var i = arr.length; i; i--) {
>> // do something with arr[i]
>> }
>
> No, these are both wrong. They access an undefined element first, and
> neither accesses element 0.
>
>> var i = arr.length;
>> while (i--) {
>> // do something with arr[i]
>> }
>
> This one is correct.
>
> <snip>
I shall shut up now.
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-17 13:34 +0200 |
| Message-ID | <XnsA49D8A0BF424eejj99@194.109.133.246> |
| In reply to | #27703 |
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote on 17 mei 2015 in
comp.lang.javascript:
> No, these are both wrong. They access an undefined element first, and
> neither accesses element 0.
>
>> var i = arr.length;
>> while (i--) {
>> // do something with arr[i]
>> }
>
> This one is correct.
>
as is,
but here,
there is no effective difference between i-- and --i:
for (var i=arr.length;i;i--){
// do something with arr[i-1];
};
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web