let arr = [1,4,6]
let len = arr.length
let temp = 0
for(let i=0; i<Math.floor(arr.length/2); i++){
let x = i
let y = len-1-i
temp = arr[x]
arr[x] = arr[y]
arr[y] = temp
}
console.log(arr)
let arr = [1,4,6]
let len = arr.length
for(let i=0; i<Math.floor(arr.length/2); i++){
let x = i
let y = len-1-i
arr[x] = arr[x] ^ arr[y]
arr[y] = arr[x] ^ arr[y]
arr[x] = arr[x] ^ arr[y]
}
console.log(arr)
let arr= [1,2,3]
arr.reverse()
let arr=[1,2,3], res =[]
for(let i=arr.length-1; i>=0; i--) {
res = arr[i]
}
console.log(res)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
temp swap | |
xor swap | |
inbuilt | |
manual rvers |
Test name | Executions per second |
---|---|
temp swap | 123531.7 Ops/sec |
xor swap | 107936.8 Ops/sec |
inbuilt | 42128328.0 Ops/sec |
manual rvers | 169890.8 Ops/sec |