Hello!
Help me, please, here I have a two-dimensional array. I need to create a second array and copy the contents of the first one in reverse order! help me please
- one@timka, According to the rules of the forum, questions should not be reduced to the decision or the completion of student assignments. Please clarify what you have done yourself and what did not work out. - fori1ton
|
1 answer
Use the method / function (not sure how correctly in javascript this is called) reverse
arr = [1,2,3] a = arr.reverse() // в "а" у вас теперь будет массив [3,2,1]
- I apologize, I didn’t have to write without needing any methods in the cycle to do it all - timka
- I have a two-dimensional array. I need to create a second array to copy the contents of the first array into it in the reverse order using a loop, please help - timka
- @timka, and how to do for a one-dimensional array - you understand? For two-dimensional - it is similar, only two indices, but not one. - avp
- Could you show something like this in code? - timka
- See (pseudocode), here you have 2 arrays A [N] and B [N] (indexed from 0, i.e. contain elements A [0], A [1], ... A [N-1]) , code for (i = 0; i <N; i ++) B [i] = A [i]; copies array A to array B, and the code for (i = 0; i <N; i ++) B [N - 1 - i] = A [i]; will copy array A into array B in reverse order. If we have two-dimensional arrays A [N] [M] and B [N] [M], then for (i = 0; i <N; i ++) for (j = 0; j <M; j ++) B [i] [j] = A [i] [j]; copies the two-dimensional array A to B in direct order. - And now, by analogy, write yourself copying in the reverse order. - avp 7:54 pm
|