Two Pointer Algorithm In Js