Setting the following:
Change all elements in the array in places, that is, the one that was 10th, Make 1st. The one was 9th, make 2nd and so on.
I do and nothing works, more precisely the first five changes and then not.
Here is the code:
var arr = new array (1,2,3,4,5,6,7,8,9, ten);
var arr_2 = arr;
var i = 0;
VAR Count = Arr.Length;
for (i = 0; i & lt; arr.length; i ++) {
Document.Write (Arr [i] + '');
}
Count = Count-1;
i = 0;
for (i = 0; i & lt; arr.length; i ++) {
ARR [i] = ARR [COUNT];
ARR [COUNT] = ARR_2 [I];
Count = Count-1;
}
Document.Write ('& lt; br & gt;');
for (i = 0; i & lt; arr.length; i ++) {
Document.Write (Arr [i] + '');
}
1, Authority 100%
I’ll just leave it to do: http://javascript.ru/array/reverse
2, Authority 14%
Well, as BE, you need another variable here
for (i = 0; i & lt; = count / 2; i ++) {
var t = arR [COUNT-I];
ARR [COUNT-I] = ARR [I];
Arr [i] = T;
}
And then you have arrays – this is the same object as it is created through New.
Learn the programming language on which you write
3, Authority 7%
As I understand it at the start), respectively, you need the easiest solution without methods, here it is:
for (i = arr.length-1; i & gt; = 0; i--) {
Document.Write (Arr [i] + '');
}
4, Authority 7%
Here this option
var arr = [0,1,2,3,4,5,6,7,8,9] ;
VAR TEMP;
for (var i = 0, j = arr.length-1; i & lt; j; i ++, j--)
{
temp = arr [j];
arr [j] = arr [i];
ARR [I] = TEMP;
}
Document.getelementByid ('Result'). Innerhtml = (ARR);
At one time, in the first year, success was due to the use of complexity O (N / 2) .
is not always inferior to the built-in array.reverse ()
5, Authority 7%
Try it:
arr.reduce ((p, c) = & gt; {c + = p; return c;}, '' ) .split``;
and what changes are simply analog.
6
If you do not want to use Sort or the second variable, then this is such a parsley:
var arr = new array (1,2,3,4,5,6,7,8,9, ten);
var newarr = [], index;
For (i = arr.length; i & gt; 0; i--) {
index = Arr.Length - I;
newArr [i] = Arr [index];
}
Console.log (NewArr);
7
function sortfunction (a, b) {
IF (A & LT; B)
Return 1;
if (a & gt; b)
Return -1;
Return 0.
}
Var Arr = New Array (1,2,3,4,5,6,7,8,9,10);
Console.log (Arr.Sort (SortFunction));
Now in Russian. JavaScript has the SORT method in which we pass our sort function. Read more here