Two Pointer Algorithm Javascript Array Functions