Aryan PrajapatKnowledge Contributor
How do you reversing an array
How do you reversing an array
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
Create a function that takes an array, start index, and end index of the array as parameters. Swap the elements present at the start and end index, The portion of the array left to be reversed is arr[start+1,end-1]. Make a recursive call to reverse the rest of the array.
You can use the reverse() method to reverse the elements in an array. This method is useful to sort an array in descending order. Let’s see the usage of reverse() method in an example,
let numbers = [1, 2, 5, 3, 4];
numbers.sort((a, b) => b – a);
numbers.reverse();
console.log(numbers); // [1, 2, 3, 4 ,5]