Two Pointer Algorithm Javascript Array