function compareNumbers(x, y) {
return x - y;
}
var a = [3,6,2,7,8,10,43] //I have one array
var b = a.slice().sort(compareNumbers).reverse(); //I reverse this array
//Now I have 2 arrays
a = [3,6,2,7,8,10,43]
b = [43, 10, 8, 7, 6, 3, 2]
My Question: I want to find the neighbour element of b in array a. For example:
b[0] that is 43 , want to find both neighbour of 43 in array a. // 10
b[1] that is 10 , want to find both neighbour of 10 in array a. // 43,8
b[6] that is 2, want to find both neighbour of 2 in array a. // 6,7