Two Pointer Algorithm Javascript Array Splice