?? ?? Reverse the Array without using built in function Day - 7!?? ??
Sanjeev Kumar
Senior Developer | Backend Development Specialist in Node.js & MongoDB | Angular Expertise for Dynamic Frontend Solutions | AWS
let arr = [10,2,5,20,23,53,54];
let low = 0;
let high = arr.length - 1;
while(low < high) {
let temp = arr[low]
arr[low] = arr[high]
arr[high] = temp
low++
high--
}
console.log("arr------->",arr)
In this problem we will run while loop until low is less than high index. Than we need to store low in the temp.
Replace low with high and high with temp variable.
Than we increase the low(low is starting index) and less the high(high is last index).
Angular developer
1 年let abc = [1, 2, 3, 4, 5, 6, 7]; let newArray = []; for (i = abc.length - 1; i >= 0; i--) { ?newArray.push(abc[i]) } console.log(newArray)
Senior Software Engineer @ Uneecops Technologies Ltd. | MCA
1 年Thanks for sharing