?? ?? Reverse the Array without using built in function Day - 7!?? ??

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).


Anil Kumar

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)

回复
Harish Kumar

Senior Software Engineer @ Uneecops Technologies Ltd. | MCA

1 年

Thanks for sharing

回复

要查看或添加评论,请登录

Sanjeev Kumar的更多文章

社区洞察

其他会员也浏览了