In this question, the candidate needs to implement a function
customReverse that mimics the behaviour of
reverse() method reverses an array in place and returns the reference to the same array, the first array element now becoming the last, and the last array element becoming the first. In other words, elements order in the array will be turned towards the direction opposite to that previously stated.
const array = ['one', 'two', 'three']; console.log('array:', array); // expected output: "array:" Array ["one", "two", "three"] const reversed = array.reverse(); console.log('reversed:', reversed); // expected output: "reversed:" Array ["three", "two", "one"] // Careful: reverse is destructive -- it changes the original array. console.log('array:', array); // expected output: "array:" Array ["three", "two", "one"]
The reference to the original array, now reversed. Note that the array is reversed in place, and no copy is made.
Start the timer, complete your solution, and test it against the test cases provided by the platform. Ideally, you should finish this question within 30 mins. Share your solution with us -- https://twitter.com/devtoolstech