//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"]
/*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 ( ͡~ ͜ʖ ͡°)