niharikapujari

Niharika Pujari

Posted on August 24, 2020

Reverse Array

Problem:

Write two functions reverseArray and reverseArrayInPlace. The first, reverseArray, takes an array as an argument and produces a new array that has the same elements in the inverse order. The second, reverseArrayInPlace, does what the reverse method does: it modifies the array given as argument in order to reverse its elements. Neither may use the standard reverse method.

Method 1: ReverseArray

Alt Text

Method 2: ReverseArrayInPlace

Alt Text

Which one is better? ReverseArrayInPlace : ReverseArray

ReverseArrayInPlace takes half the time and will replace two values at a time instead of looping the whole array and replacing the values one at a time.

💖 💪 🙅 🚩
niharikapujari
Niharika Pujari

Posted on August 24, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Self-Learning JavaScript Journey
beginners Self-Learning JavaScript Journey

December 16, 2021

Mad Max: Journey to the ThunderDOM!!!
beginners Mad Max: Journey to the ThunderDOM!!!

October 15, 2020

Reverse Array
beginners Reverse Array

August 24, 2020