Making sure that all elements are distinct array elements and an element is not considered more than once .
let p = mp . get ( X - sum ) ; if ( p [ 0 ] != i && p [ 0 ] != j && p [ 1 ] != i && p [ 1 ] != j ) { document . write ( arr [ i ] + " " + arr [ j ] + " " + arr [ p [ 0 ] ] + " " + arr [ p [ 1 ] ] ) ; return ; } } } } }