Hello, I was trying to denote the last element of an array but I find it pretty confusing. Let me show you.
what you can see here is getting the last element of an array.
Hi, it’s not an fcc challenge. Rather I took the concept from this website and been applying this algorithm for array reversal. It seems I am on the verge of success but… I am stuck !
As a novice programmer, I find it difficult. could you please show me what the indices should be? I feel that the problem lies in right here… swap (arr, arr[0], arr[arr.length-1]);
well, I was just figuring out in what ways can I write a program for this array reversal. It seems this method was never used to reverse an array. May be I am wrong. But you see, it was working.
Well maybe you can explore this method if you like but first make sure you know how to do it the normal way. That is, a simple for loop and write the values into a new array in reverse.
If you get that working, the. Try to use other methods like swapping.
I tried the way you said…but it’s not working. could you please share the code? I mean is it possible to reverse an array using this method? If not then I’ll quit.
just gonna give you my 2 cents and be gone…
I strongly suggest that you go back and look at the fCC javascript course if you haven’t already.
Understanding some fundamentals first of coding will greatly help you.
An array is a data structure which represents a collection of items stored at contiguous memory locations.
Elements in an array are referenced by an index starting from zero (depending on the language)
arr = [1, 2, 3]
the first element is referenced by a[0], that is element at index 0, second by a[1], that is element at index 1, in that order.
so start and end should denote the start and end indexes in the array you want to reverse.
you can either pass them as arguments to the function like you did initially or set them to default to the index, (0) and index (arr.length - 1).
I hope this finds you well.