//The reverse() method reverses the elements in an array.const fruits =["Banana","Orange","Apple","Mango"];
fruits.reverse();//output >> ["Mango", "Apple", "Orange", "Banana"]//if you find the answer is useful ,//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
constreverseString=(str)=>{const revArray =[];const length = str.length-1;// Looping from the endfor(let i = length; i >=0; i--){
revArray.push(str[i]);}// Joining the array elementsreturn revArray.join('');}//if you find this answer is useful ,//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
#The original array
arr =[11,22,33,44,55]print("Array is :",arr)
res = arr[::-1] #reversing using list slicing
print("Resultant new reversed array:",res)
// reverse array elements in javascriptconst arr =["first","second","third"];
arr.reverse();// Mutates the arrayconsole.log(arr);// ["third", "second", "first"]
// reversing an array in javascript is kinda hard. you can't index -1.// but i can show how you can do it in 4 lines.var myArray =[1,2,3,4,5,6,7,8,9,10];for(var i = myArray.length-1; i >0; i -=1){
myArray.shift();
myArray.push(i);}console.log(myArray);// output: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
/*method to reverse a linked list */reverse(list){let current = list.head;let prev =null;let next =null;if(this.head){//only one nodeif(!this.head.next){returnthis;}while(current){
next = current.next;//store next node of current before change
current.next= prev;//change next of current by reverse the link
prev = current;//move prev node forward
current = next;//move current node forward}
list.head= prev
return list
}return"is empty"}
const array1 =['one','two','three'];console.log('reversed:', array1.reverse());// Note that reverse() is destructive -- it changes the original array.console.log('array1:', array1);// expected output: "array1:" Array ["three", "two", "one"]
constreverseArray=(arr)=>{for(let v = arr.length; v >0; v--){return arr[v];}}//if you find this answer is useful ,//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)